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

Don't escape period characters with wildcard searches in mysql2 #1013

Merged

Conversation

daflip
Copy link
Contributor

@daflip daflip commented Apr 11, 2019

ransack is currently escaping period characters in mysql2. This is not correct and makes it impossible to search for things with periods in it (like email addresses). In my limited experience with Postgres I believe it's correct to escape it there -- my patch splits the Postgres vs Mysql2 logic so the escaping for Postgres is left unchanged.

irb(main):001:0> unescaped = "je_rry.walsh|h%"
irb(main):002:0>          unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
=> "je\\_rry\\.walsh|h\\%"
irb(main):003:0>          unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1')                                                                                                              
=> "je\\_rry.walsh|h\\%"

Only % and _ should be escaped since these are the only pattern characters supported in mysql:
https://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html

@daflip daflip changed the title Don't escape period characters in mysql2 Don't escape period characters with wildcard searches in mysql2 Apr 12, 2019
@scarroll32 scarroll32 merged commit 7836838 into activerecord-hackery:master Jun 5, 2019
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.

2 participants