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

slug() - returns an empty string in some locales #2103

Open
kymckay opened this issue Sep 17, 2024 · 2 comments · May be fixed by #2104
Open

slug() - returns an empty string in some locales #2103

kymckay opened this issue Sep 17, 2024 · 2 comments · May be fixed by #2104

Comments

@kymckay
Copy link

kymckay commented Sep 17, 2024

  • Faker version: 28.4.1
  • OS: Mac

When using certain locales (e.g. jp_JP), the slug fake returns an empty string. I had a quick look and this is probably because the slugify decorator disallows unicode characters (which makes sense) and the fake is using the text fake under the hood - not anticipating that it is going to return unicode characters.

Steps to reproduce

  1. fake = Faker("jp_JP")
  2. fake.slug()

Expected behavior

The slug fake should never return an empty string

Actual behavior

The slug fake returns an empty string in some locales.

@kymckay
Copy link
Author

kymckay commented Sep 17, 2024

I think the best effort behaviour here would be to return a slug with English characters, so it'd return an ascii slug even though it doesn't contain Japanese characters. This mimics the fallback behaviour of locale providers in general.

This fake is particularly problematic when in multi locale mode - where you only sometimes get an empty string because of certain locales. You may want to generate multi-locale text, but to still generate valid slugs without instantiating a separate generator only set to English for that purpose.

@Pandede
Copy link
Contributor

Pandede commented Sep 17, 2024

I think the best effort behaviour here would be to return a slug with English characters, so it'd return an ascii slug even though it doesn't contain Japanese characters. This mimics the fallback behaviour of locale providers in general.

This fake is particularly problematic when in multi locale mode - where you only sometimes get an empty string because of certain locales. You may want to generate multi-locale text, but to still generate valid slugs without instantiating a separate generator only set to English for that purpose.

This is a fair point, maybe make slug() always generate texts in locale en_US regardless of the assigned locale?

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 a pull request may close this issue.

2 participants