Skip to content

Bug: AirtableApiClient.php's addFilter() should escape quotes in filter target $value #82

@ChrisHardie

Description

@ChrisHardie

If I run a basic field search using a string that contains quotes:

Airtable::where('Story', 'He said "no"')->get();

I receive an error:

{
    "error": {
        "type": "INVALID_FILTER_BY_FORMULA",
        "message": "The formula for filtering records is invalid: Invalid formula. Please check your formula text."
    }
}

I think this is because addFilter() in AirtableApiClient.php is passing the string value through to Airtable without escaping the quotes, confusing the filter:

$this->filters[] = "{{$column}}{$operation}\"{$value}\"";

[2024-05-20 17:01:29] local.DEBUG: Filters: Array
(
    [0] => {Story}="He said "no""
)

If I escape the quotes in my text, it works.

Airtable::where('Story', 'He said \"no\"')->get();

[2024-05-20 17:02:01] local.DEBUG: Filters: Array
(
    [0] => {Story}="He said \"no\""
)

(There may be a better way to handle this more broadly in constructing API queries than just escaping quotes, but that's as far as I got.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions