Skip to content

Request _renderFilterParams fails when filter target contains parens #203

@mbecroft

Description

@mbecroft

When a filter target contains parens, e.g.:
collection.filter({foo: 'abc(def)'})`
The resulting URI does not have escape parens. This causes problems with RQL backends where unescaped parens have special meanings such as operator precedence and so forth. Clearly, the text of the filter target has to have its parens escaped.

Request._renderFilterParams uses encodeURIComponent() to encode the filter target. encodeURIComponent() specifically does not encode parens per spec.

According to RFC3986, parens are Reserved Characters, which may need to be encoded depending on the context. Clearly, in this context, the parens should be encoded.

A trivial fix that appears to work is to replace the parens when rendering the target in the final string as follows:

return [encodeURIComponent(args[0]) + '=' + (type === 'eq' ? '' : type + '=') + encodeURIComponent(target).replace(/\(/g, "%28").replace(/\)/g, "%29")];

It is unclear to me whether this is a complete solution, but it at least works for the simple case of equality filters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions