Skip to content
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

[11.x] slug() with alphanumeric separator #54446

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

faissaloux
Copy link
Contributor

@faissaloux faissaloux commented Feb 3, 2025

Fixes #54444

This PR made slug() fallback to default separator (-) when an alphanumeric separator been passed.

Examples

Before

str('nad')->slug('az'); // nazd

After

str('nad')->slug('az'); // nad

str('hello world')->slug('e'); // hello-word
str('hello world')->slug('2'); // hello-word

@shaedrich
Copy link
Contributor

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.

@rodrigopedra
Copy link
Contributor

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:

$ php artisan tinker
Psy Shell v0.12.7 (PHP 8.2.27 — cli) by Justin Hileman
> str('футбольный')->slug()
= Illuminate\Support\Stringable {#6608
    value: "futbolnyi",
  }

> str('футбольный')->slug('ru')
= Illuminate\Support\Stringable {#6632
    value: "frutbolnyi",
  }

> str('футбольный')->slug('-')
= Illuminate\Support\Stringable {#6626
    value: "futbolnyi",
  }

> str('футбольный')->slug(language: 'ru')
= Illuminate\Support\Stringable {#6612
    value: "futbolnyy",
  }

Blindly replacing ru by - when the language parameter is not specified correctly would result in an unexpected slug, as outlined in the examples above.

I commented in the issue, recommending the user to use a named parameter to properly specify the language parameter:

#54444 (comment)

@vlakoff
Copy link
Contributor

vlakoff commented Feb 4, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird behavior of Str::slug in particular language
4 participants