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

fix: parse accept-language prefixes #64

Closed

Conversation

strangedev
Copy link

@strangedev strangedev commented Feb 1, 2021

This is a work-in-progress for fixing #63.

We also have some questions concerning the order of precedence when parsing the accept language.
This test seems to imply in its description that when both en-GB and en are both offered by the server and accepted by the client, en-GB should always be chosen, as it is more specific than en. Are we missing something here?

@dotKuro and I plan on refactoring and testing this tomorrow.

Co-authored-by: Alexander Kampf <mail@akampf.dev>
@devinivy
Copy link
Member

devinivy commented Feb 2, 2021

Hey, thanks for the help! My interpretation is the same as yours: I believe that we have two bugs here. I have a couple thoughts:

  1. It looks like we have 100% coverage, but it would still be great to get a failing test for the original bug.
  2. I wonder if it would be a fruitful approach to expand preferences when it is normalized into lowers. For example, preferences such as ['de-DE', 'en-CA', 'fr'] would be normalized into a map with keys de-de, de, en-ca, en, fr. The goal would be to minimize exceptions throughout the code for accept-language and minimize the computation involved in matching. Does that seem like a workable approach?

@devinivy devinivy added the bug Bug or defect label Feb 2, 2021
@strangedev
Copy link
Author

strangedev commented Feb 2, 2021

Hey @devinivy 👋
Thank you for the quick response! We're pretty pleased with how this has been handled so far ☺️

We liked your idea of normalizing the preferences into the map and refactored the code to use this approach. With the new approach, we've only introduced two new conditionals in total and only one of those is specific to accept-language 😊

We've also added a test for the fix.

Hopefully the code is up to standard. If there's anything we should improve, please let us know!

@devinivy
Copy link
Member

devinivy commented Feb 5, 2021

@dotKuro @strangedev many thanks for this contribution. I see that you weighed-in on #65 and support that approach and behavior, which was important feedback to ensure the bug you raised was addressed. It seems like that is the direction we should go (I realize just how similar the implementations are!) so I'm closing this, but again your work and review is appreciated.

@devinivy devinivy closed this Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants