Closed kylestew closed 9 years ago
Ah yes, didn't think about that case.
The most efficient way to resolve this with no extra queries would be to look for -X at the end of a potential slug where X is any number of digits. Would reduce multiple sets as well, so the following example would occur:
test
, slugs as test
test
, slugs as test-1
test-1
, slugs as test-2
test-1-2-3-4-5
slugs as test-3
test-1-abc
, would still slug as test-1-abc
Probably less than ideal for edge cases like 3 and 4, but would guarantee distinct slugs. This is the most efficient way to handle these cases. Do you think this would work for your situation?
Yes, this seems like it would work great. Its an edge case, so the goal is to make sure there isn't a chance for the slug to be ambiguous and cause links to not be unique. If users are doing crazy '-123' stuff with their names, they may get a weird slug link. Thats ok.
Do you see this being implemented in the library?
Done - released 0.3.0
It's kind of an edge case, but there is a way to cause multiple slugs to be the same even when
distinct
is set to true.test
, slug will be generated astest
test-1
test-1
and slug value will also betest-1
making two slugs the same in the databaseIt seems like we can fool the slug system if we throw a un-slugged string that matches an existing incremented slug. I'm using slugs as unique URLs, so there is the case where it will incorrectly match a URL.
Any ideas on how this could be fixed? This is the only shortcoming I see with this library, otherwise its great and I hope to continue to use it.