Skip to content

Issue escaping regex partial newline-sensitive matching #28

@pete-rai

Description

@pete-rai

The code inserts partial newline-sensitive matching into regex expressions when required. For example, this query:

{"name":{ "$regex":"forest"}}

correctly leads to:

record->>'name' ~ '(\?p)forest'

However, when more than one is present, only the first one escapes the question mark. For example, this query:

{"$or":[{"name":{ "$regex":"forest"}},{"entity.description":{ "$regex":"forest"}}]}

incorrectly leads to:

(record->>'name' ~ '(\?p)forest' OR record->'entity'->>'description' ~ '(?p)forest')

Here the latter (?p) should be (\?p). Without the escaped question-mark, Postgres interprets this as a replacement parameter.

A workaround for this is to escape such instances manually after the convert:

where.replaceAll(/'\(\?([^\)]+)\)/g, "'(\\?$1)");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions