Add treat_numeric_as_conflict option to prevent ambiguous numeric slugs#1
Closed
Add treat_numeric_as_conflict option to prevent ambiguous numeric slugs#1
Conversation
3864f3c to
d0c552d
Compare
Author
|
Opened as norman#1037 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new configuration option
treat_numeric_as_conflictto resolve the ambiguity whereModel.friendly.find("123")could return either a record withslug="123"OR a record withid=123.When enabled, purely numeric slug candidates are treated as conflicts and resolved using UUID suffixing, ensuring all slugs contain non-numeric characters that eliminate lookup ambiguity.
Changes
treat_numeric_as_conflictconfiguration option toSlugged::ConfigurationSlugGeneratorto detect and reject purely numeric slugs when enabledpurely_numeric_slug?helper method usingInteger()validation (consistent withpotential_primary_key?)Usage
Testing Done
Deploy Notes
Fixes
Addresses the ambiguous lookup issue reported in norman#276 where
User.find('123-foobar')could incorrectly return a user withid=123instead of searching for the intended slug.