Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue escaping regex partial newline-sensitive matching #28

Open
pete-rai opened this issue Jun 23, 2022 · 0 comments
Open

Issue escaping regex partial newline-sensitive matching #28

pete-rai opened this issue Jun 23, 2022 · 0 comments

Comments

@pete-rai
Copy link

pete-rai commented Jun 23, 2022

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)");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant