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

We need to do a better job of converting SQL LIKE expression into Regex #719

Closed
hackel opened this issue Feb 2, 2016 · 4 comments
Closed

Comments

@hackel
Copy link
Contributor

hackel commented Feb 2, 2016

In \Jenssegers\Mongodb\Query\Builder::compileWhereBasic, the conversion from an SQL LIKE expression to a MongoRegex is incomplete. A quick search revealed a more complete implementation here: http://stackoverflow.com/a/11436643/4186945 Specifically, it should at least be calling preg_quote on the input parts that aren't operators (% and _). You could leave quoting % and _ up to the developer, since that's what one would have to do with a SQL DB.

This bit me when trying to do a like query on an email address that contained a + character, that ends up going unescaped. For now I'm just running preg_quote myself, but unfortunately that will break once this is fixed. :-/

@jenssegers
Copy link
Contributor

Should be fixed in master :)

jenssegers added a commit that referenced this issue Feb 3, 2016
@hackel
Copy link
Contributor Author

hackel commented Feb 4, 2016

Brilliant, thanks. This still doesn't cover % appearing mid-string, or _ at all, but I'm not using that personally. Obviously people should be using a proper regex for that anyway. This still allows me to use a library that runs a like query on my models.

@jenssegers
Copy link
Contributor

It should. All %'s get replaced by .*

@hackel
Copy link
Contributor Author

hackel commented Feb 4, 2016

Bah, yes sorry, I was just testing and realised that. Excellent!

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

2 participants