Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

fix(intl): support wildcard for Accept-Language header #31

Merged
merged 1 commit into from
May 5, 2021

Conversation

smackfu
Copy link
Member

@smackfu smackfu commented May 4, 2021

Description

Set the activeLocale to the default locale when a wildcard is passed for Accept-Language.

Motivation and Context

If the Accept-Language header on a request is set to "*", the value of the activeLocale in state will also be set to "*", which is not generally going to be a valid locale value by consumers.

For instance, if passed to react-intl, the following error occurs:

RangeError: '*' is not a structurally valid language tag

Using a wildcard for Accept-Language is not common but it is in the spec: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language

Fixes #30.

How Has This Been Tested?

Fix was straightforward so primary testing was in unit tests.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My changes are in sync with the code style of this project.
  • There aren't any other open Pull Requests for the same issue/update.
  • These changes should be applied to a maintenance branch.
  • This change requires cross browser checks.
  • This change impacts caching for client browsers.
  • This change adds additional environment variable requirements for one-app-ducks users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using one-app-ducks?

If someone was dependent on the activeLocale being set to "*", their code may stop working properly.

@smackfu smackfu requested review from a team as code owners May 4, 2021 18:09
@nellyk
Copy link
Contributor

nellyk commented May 5, 2021

@smackfu Thank you!

Copy link
Contributor

@infoxicator infoxicator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are technically forcing the default language instead of the wildcard because libraries like react-intl don't support it (even though it is in the spec). I am happy having this opinion and falling back to en-US similar to when the header is not present.

Do we foresee a case when someone wishes to use the wildcard and because this is not documented they could have a hard time finding out why it doesn't work as they expect?

@smackfu
Copy link
Member Author

smackfu commented May 5, 2021

@infoxicator In my opinion, defaulting to any particular hardcoded language isn't great, but this change doesn't really make it worse.

@JAdshead
Copy link
Contributor

JAdshead commented May 5, 2021

* means any language so i take it as it leaves it up to the application to choose, falling back the default makes sense.

@JAdshead JAdshead merged commit 28cb8c2 into americanexpress:main May 5, 2021
oneamexbot added a commit that referenced this pull request May 5, 2021
## [4.3.2](v4.3.1...v4.3.2) (2021-05-05)

### Bug Fixes

* **intl:** support wildcard for Accept-Language header ([#31](#31)) ([28cb8c2](28cb8c2))
@oneamexbot
Copy link
Contributor

🎉 This PR is included in version 4.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

"Accept-Language: *" header incorrectly sets activeLocale to "*"
5 participants