Commits

Sergey Schetinin  committed 291a6b2

make sure that `'en' in AcceptLanguage('en-gb')` and `'en_GB' in AcceptLanguage('en-gb')`

  • Participants
  • Parent commits 6689fbd

Comments (0)

Files changed (2)

File tests/test_acceptparse.py

         ('da', 'DA'),
         ('en', 'en-gb'),
         ('en-gb', 'en-gb'),
+        ('en-gb', 'en'),
+        ('en-gb', 'en_GB'),
     ]:
         assert lang in AcceptLanguage(mask)
-    assert 'fr-fr' not in AcceptLanguage('en-gb')
+    for mask, lang in [
+        ('en-gb', 'en-us'),
+        ('en-gb', 'fr-fr'),
+        ('en-gb', 'fr'),
+        ('en', 'fr-fr'),
+    ]:
+        assert lang not in AcceptLanguage(mask)
 
 # NilAccept tests
 

File webob/acceptparse.py

 
 class AcceptLanguage(Accept):
     def _match(self, mask, item):
+        item = item.replace('_', '-').lower()
+        mask = mask.lower()
         return (mask == '*'
-            or item.lower() == mask.lower()
-            or item.lower().split('-')[0] == mask.lower()
+            or item == mask
+            or item.split('-')[0] == mask
+            or item == mask.split('-')[0]
         )