-
-
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
Case Insensitivity for id
, fixes #785
#787
Conversation
4 similar comments
+1 |
Could I know this is merged or not yet? |
I was just wandering around this repo and found this PR, which is identical to the change I have overridden locally. Would be great to see this merged. 👍 |
id
, Fix #785id
, fixes #785
I just realized there could be couple of issues with this PR: What if |
All the tests passed, so perhaps if we had tests for those cases, we could fix that preemptively. Are you keen @vfonic ? |
This was a bad merge. It is a breaking change and has. no opt-in or opt-out behavior. There are many valid reasons for allowing a URL to have case-sensitive slugs, such as short URL services. It should, at the very least, use the |
@coneybeare thanks, I see what you mean. Do you have a patch in mind that would fix this for you, that you could open a pull request for? Or if you just want to share a snippet I can turn it into a PR. |
I’m AFK now, but how about adding a method that defaults one way or the other, and can be overridden in the model to change if necessary? That is the pattern used by the normalize process |
yep, that would make sense to me.. something like |
That's a good idea. It could also be a config option: |
I like that too! |
FWIW, this broke my implementation. I use FriendlyId for usernames, and some usernames are stored with capitalization in the database. For example If we want FriendlyId to be truly case insensitive we should also downcase the attribute we're matching on (e.g. |
Yeah, the comments on this PR didn't result in any patches unfortunately. I'm all for making this work for everyone. For now, you can use 5.3.0 and I still think @vfonic's suggestion is the best one about making this a config option (probably that defaults to false) |
In #787 we merged a change which found slugs by `id.downcase` by default, but this has understandably caused issues for other users of FriendlyId who don't want to do this. This reverts that change and introduces a new method, `parse_friendly_id`, which can be overridden similar to `normalize_friendly_id`. Instead of being used for slug generation, `parse_friendly_id` is used for parsing incoming slugs. Fixes #950
Hello. This PR is about fixing the first issue of #785 by using
id.downcase
instead ofid
infirst_by_friendly_id
method. In this way if the url is likeusers/John-Doe
orusers/JOHN-DOE
, it will search byjohn-doe
in database.Currently, it
find_by
withid
.(case-sensitive)It
find_by
with id.downcase.(case-insensitive)The tests for the change have been added and all have passed.