From a0bf87d7e397f65a1b6ca856bfc887239cbc3830 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 2 Dec 2020 15:00:09 -0800 Subject: improve Accept-Language header parsing --- fatcat_scholar/hacks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fatcat_scholar') 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"]) -- cgit v1.2.3