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

Provide a fallback for LanguageAccept under Safari #1507

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@chivalry
Copy link
Contributor

commented Apr 6, 2019

Safari on macOS doesn't provide a language-only option in the header for languages accepted. When en-US is the preferred language, Safari only provides an "Accepted Language" of en-US without any fallback to en. Therefore, if a website is offering an en language version but not an en-US version, LanguageAccept.best_match returns None.

This pull request attempts to correct that by checking if None is returned and if so, trying again with language-only accepted values.

@chivalry

This comment has been minimized.

Copy link
Contributor Author

commented Apr 8, 2019

It appears this is a known issue? #450

It looks like there might be a better way to do this than what I came up with. I'll do a bit more research when I have time. For the time being my app is using my own function instead of best_match.

@chivalry

This comment has been minimized.

Copy link
Contributor Author

commented Apr 24, 2019

After some research, I don't see a better way to handle this, but I did add some additional tests.

@chivalry

This comment has been minimized.

Copy link
Contributor Author

commented Apr 24, 2019

Have the tests become more strict? Did I miss something? The tox app says there are failures in tests/test_test.py and src/werkzeug/debug/__init__.py, but my commit's version of those files is the same as in pallets:master.

@davidism

This comment has been minimized.

Copy link
Member

commented Apr 25, 2019

You need to follow the style checks, in this case ensure you use Black to format the code. You can see the changes it wants to make here: https://travis-ci.org/pallets/werkzeug/jobs/524209888#L219-L262 You can install pre-commit to have this done automatically before commits.

@davidism

This comment has been minimized.

Copy link
Member

commented Apr 25, 2019

There are three issues related to accept matching: #20, #450, and #458. I think the first comment in #20 may be listing the other two, but it would be good to review them.

@davidism davidism requested a review from ThiefMaster Apr 25, 2019

Show resolved Hide resolved src/werkzeug/datastructures.py Outdated
Show resolved Hide resolved src/werkzeug/datastructures.py Outdated

@davidism davidism added this to the 1.0 milestone May 12, 2019

chivalry added some commits Apr 6, 2019

@davidism davidism removed the request for review from ThiefMaster Jul 14, 2019

@davidism davidism force-pushed the chivalry:lang-accept-fallback branch from d89e73d to a61e6d6 Jul 14, 2019

@davidism

This comment has been minimized.

Copy link
Member

commented Jul 14, 2019

This doesn't go the opposite direction, where the client accepts "en", but the server looks for "en_US". Is that intended / correct?

a = LanguageAccept((("en", 0.9),))
m = a.best_match(("en_US",))
print(m)  # None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.