Ticket #16322: allow-spaces-in-accept-language.diff

File allow-spaces-in-accept-language.diff, 1.7 KB (added by Max Arnold <lwarxx@…>, 13 years ago)

patch with tests

  • django/utils/translation/trans_real.py

    diff -Naur Django-1.3.orig/django/utils/translation/trans_real.py Django-1.3/django/utils/translation/trans_real.py
    old new  
    3030
    3131# Format of Accept-Language header values. From RFC 2616, section 14.4 and 3.9.
    3232accept_language_re = re.compile(r'''
    33         ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)   # "en", "en-au", "x-y-z", "*"
    34         (?:;q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
    35         (?:\s*,\s*|$)                            # Multiple accepts per header.
     33        ([A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*|\*)         # "en", "en-au", "x-y-z", "*"
     34        (?:\s*;\s*q=(0(?:\.\d{,3})?|1(?:.0{,3})?))?   # Optional "q=1.00", "q=0.8"
     35        (?:\s*,\s*|$)                                 # Multiple accepts per header.
    3636        ''', re.VERBOSE)
    3737
    3838def to_locale(language, to_lower=False):
  • tests/regressiontests/i18n/tests.py

    diff -Naur Django-1.3.orig/tests/regressiontests/i18n/tests.py Django-1.3/tests/regressiontests/i18n/tests.py
    old new  
    553553        self.assertEqual([('de', 1.0), ('en-au', 0.75), ('en-us', 0.5), ('en', 0.25), ('es', 0.125), ('fa', 0.125)], p('de,en-au;q=0.75,en-us;q=0.5,en;q=0.25,es;q=0.125,fa;q=0.125'))
    554554        self.assertEqual([('*', 1.0)], p('*'))
    555555        self.assertEqual([('de', 1.0)], p('de;q=0.'))
     556        self.assertEqual([('en', 1.0), ('*', 0.5)], p('en; q=1.0, * ; q=0.5'))
    556557        self.assertEqual([], p(''))
    557558
    558559        # Bad headers; should always return [].
Back to Top