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

Empty locale cookie crashes rendering #74

Closed
henrixapp opened this issue Sep 15, 2020 · 2 comments · Fixed by #75
Closed

Empty locale cookie crashes rendering #74

henrixapp opened this issue Sep 15, 2020 · 2 comments · Fixed by #75

Comments

@henrixapp
Copy link
Collaborator

If you supply an empty locale cookie 🥠 (done by accident while testing), the application renders an error and is unusable.

The culprit is here https://github.com/fosterfarrell9/mampf/blob/f117f860a277e6219183861605c0aadc17f4fb58/app/controllers/application_controller.rb#L80

This causes the enforce_available_locales! to crash, because the locale "" is unknown.

A possible way to mitigate this, would be:

if cookies[:locale].in?(I18n.available_locales.map(&:to_s))
  cookie_param = cookies[:locale]
end
I18n.locale = current_user.try(:locale) || locale_param ||
                    cookie_param || I18n.default_locale
fosterfarrell9 added a commit that referenced this issue Sep 16, 2020
@henrixapp
Copy link
Collaborator Author

The locale was empty because the account was created by command. I added an validation, that validates empty and correct locales, because I don't know, whether there are empty ones in the production system

@fosterfarrell9
Copy link
Collaborator

That makes sense. I just looked into the production db. Currently there are no users with missing or incorrect locales.

fosterfarrell9 added a commit that referenced this issue Sep 22, 2020
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