-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[11.x] slug()
with alphanumeric separator
#54446
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
Conversation
I don't like these silent fallbacks that might not be intuitive and therefore easily overlooked when something doesn't work as expected. Maybe, throwing an exception is more intuitive. |
I agree with @shaedrich, silent fallbacks are not intuitive at all. And this approach also does not solve the issue described, as the issue reporter expects to be using a localized slug in a different language, and the proposed solution would mask the issue further as they would expect language-specific characters to be treated in that language. For example, the word "soccer" in Russian is written as "футбольный" (according to Google Translate, I don't speak Russian). It would get different slugs depending on the language parameter:
Blindly replacing I commented in the issue, recommending the user to use a named parameter to properly specify the language parameter: |
The use case is incorrect due to an erroneous parameter, and the proposed change would not solve the issue, but rather create additional problems. This should be closed as invalid. |
I made it now throws an exception when separator is alphanumeric. Thanks all for your feedback! |
I'm not certain if this check is adequate… A more adequate check could be: if (preg_match('![\pL\pN\s]!u', $separator)) { /* throw exception */ } Using But again, I'm not convinced it would be helpful. In practice, a check enforcing that |
Though, if you look at this comment in the previous ticket:
Multi-character separators "just work" by luck (at least in some cases), and some people might be using it. Therefore, I would suggest changing nothing, i.e., don't add any check. Neither for alphanumeric separators nor for multi-character separators. As a reminder, the issue was initially due to a completely erroneous parameter… we don't have to handle that. |
We could always have some kind of setting to enable/disable this |
Fixes #54444
This PR made
slug()
fallback to default separator (-
) when an alphanumeric separator been passed.Examples
Before
After