Skip to content

Commit d718f24

Browse files
committed
Improve handling of und vs. exact matches
1 parent c7317d5 commit d718f24

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/negotiate/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
144144

145145
for req in requested {
146146
let mut req = req.as_ref().to_owned();
147-
if req.get_language() == "und" {
148-
continue;
149-
}
150-
151147
macro_rules! test_strategy {
152148
($self_as_range:expr, $other_as_range:expr) => {{
153149
let mut match_found = false;
@@ -183,6 +179,12 @@ pub fn filter_matches<'a, R: 'a + AsRef<LanguageIdentifier>, A: 'a + AsRef<Langu
183179
// 2) Try to match against the available locales treated as ranges.
184180
test_strategy!(true, false);
185181

182+
// Per Unicode TR35, 4.4 Locale Matching, we don't add likely subtags to
183+
// requested locales, so we'll skip it from the rest of the steps.
184+
if req.get_language() == "und" {
185+
continue;
186+
}
187+
186188
// 3) Try to match against a maximized version of the requested locale
187189
if req.add_likely_subtags() {
188190
test_strategy!(true, false);

tests/fixtures/negotiate/filtering/requested-und.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
{
33
"input": [["und"], ["de", "pl-PL", "it", "fr-Latn-CA", "ru"]],
44
"output": []
5+
},
6+
{
7+
"input": [["und"], ["und", "en-US"], "en-US"],
8+
"output": ["und", "en-US"]
59
}
610
]

0 commit comments

Comments
 (0)