aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_scholar
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-12-02 15:00:09 -0800
committerBryan Newbold <bnewbold@archive.org>2020-12-02 15:00:09 -0800
commita0bf87d7e397f65a1b6ca856bfc887239cbc3830 (patch)
tree7e5cc8878ffbafa847d5298ee950b4a43e27ba4e /fatcat_scholar
parent639111158b56966d4ac91150de15102bb80c1877 (diff)
downloadfatcat-scholar-a0bf87d7e397f65a1b6ca856bfc887239cbc3830.tar.gz
fatcat-scholar-a0bf87d7e397f65a1b6ca856bfc887239cbc3830.zip
improve Accept-Language header parsing
Diffstat (limited to 'fatcat_scholar')
-rw-r--r--fatcat_scholar/hacks.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/fatcat_scholar/hacks.py b/fatcat_scholar/hacks.py
index 96226ff..5cb8572 100644
--- a/fatcat_scholar/hacks.py
+++ b/fatcat_scholar/hacks.py
@@ -60,7 +60,7 @@ def parse_accept_lang(header: str, options: typing.List[str]) -> typing.Optional
"""
if not header:
return None
- chunks = [v.split(";")[0].split("-")[0] for v in header.split(",")]
+ chunks = [v.split(";")[0].split("-")[0].split("_")[0] for v in header.split(",")]
for c in chunks:
if len(c) == 2 and c in options:
return c
@@ -72,6 +72,7 @@ def test_parse_accept_lang() -> None:
assert parse_accept_lang("en,de", []) == None
assert parse_accept_lang("en,de", ["en"]) == "en"
assert parse_accept_lang("en-GB,de", ["en"]) == "en"
+ assert parse_accept_lang("zh_Hans_CN", ["en", "zh"]) == "zh"
assert parse_accept_lang("en,de", ["de"]) == "de"
assert (
parse_accept_lang("en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2", ["de"])