-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
exists?
returns false positives when query string begins with a number
#971
Comments
@corwinstephen thanks! Do you think we need to do something like |
@parndt were it up to me, I might argue that
false , though that may have other consequences I'm not aware of. An alternative could be to explicitly check to see if input.to_i != 0 there and return false if it is, and only call super after that.
It's a little bit of a tricky situation since ActiveRecord itself allows you to pass non-integer values to find, so we'd be modifying Rails behavior. But at the same time, that should only ever be a problem if someone were using friendly_id in combination with a non-numeric primary key, which would totally break anyway, so maybe that's not an issue? |
What I was meaning is that we should be using friendly ID behaviour if the slug is not fully numeric, which is what I meant by Does that help? |
@parndt if I'm not mistaken, that's what already happens. The problem stems from the fact that if the search for the friendly_id slug doesn't return anything, we then call |
yes, I think you're right @corwinstephen - if people are using |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The
exists
method falls back on ActiveRecord's implementation which runsto_i
on the input string. This means that if the slug you're searching for begins with a number, you'll get a false positive. Model.friendly.exists?('2something') ultimately performsModel.exists?(2)
, which usually returns true.The text was updated successfully, but these errors were encountered: