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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fixed contain/starts/endsWith filters with /, _ or % in them #19015

Merged
merged 1 commit into from Nov 16, 2023

Conversation

SimonBackx
Copy link
Contributor

fixes GRO-25

Updated @tryghost/nql to 0.12.0 and other packages that depend on it

  1. SQLite: when a filter string contains /.

When we use a NQL contain/starts/endsWith filter that contains a slash, underlyingly the whole filter will get converted to a MongoDB query, in which we just use a regexp to represent the filter. In here we will escape the slash: / as expected in a regexp. Later when we convert this MongoDB query back to knex/SQL, we use a SQL LIKE query. Currently we don't remove the escaping here for a normal slash. MySQL seems to ignore this (kinda incorrect). SQLite doesn't like it, and this breaks queries on SQLite that use slashes. The solution here is simple: remove the backslash escaping when converting the regexp to LIKE, just like we do with other special regexp characters.

  1. We don't escape % and _, which have a special meaning in LIKE queries

Usage of % and _ is now as expected and doesn't have the special SQL meaning anymore.

fixes GRO-25

Updated @tryghost/nql to 0.12.0 and other packages that depend on it

1. SQLite: when a filter string contains /.

When we use a NQL contain/starts/endsWith filter that contains a slash, underlyingly the whole filter will get converted to a MongoDB query, in which we just use a regexp to represent the filter. In here we will escape the slash: \/ as expected in a regexp. Later when we convert this MongoDB query back to knex/SQL, we use a SQL LIKE query. Currently we don't remove the escaping here for a normal slash. MySQL seems to ignore this (kinda incorrect). SQLite doesn't like it, and this breaks queries on SQLite that use slashes. The solution here is simple: remove the backslash escaping when converting the regexp to LIKE, just like we do with other special regexp characters.

2. We don't escape % and _, which have a special meaning in LIKE queries

Usage of % and _ is now as expected and doesn't have the special SQL meaning anymore.
@SimonBackx SimonBackx enabled auto-merge (squash) November 16, 2023 09:34
@SimonBackx SimonBackx merged commit e5f644c into TryGhost:main Nov 16, 2023
19 checks passed
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

Successfully merging this pull request may close these issues.

None yet

1 participant