Fix 400 error caused by multi-subtag language in Accept-Language header.
Reproduced by Firefox for Android in Chinese.
The regex expression is fixed according to https://datatracker.ietf.org/doc/html/rfc4647#section-2.1
Fixes: https://tracker.ceph.com/issues/51528
Signed-off-by: 胡玮文 <huww98@outlook.com>
class HomeController(BaseController, LanguageMixin):
LANG_TAG_SEQ_RE = re.compile(r'\s*([^,]+)\s*,?\s*')
LANG_TAG_RE = re.compile(
- r'^(?P<locale>[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})?)(;q=(?P<weight>[01]\.\d{0,3}))?$')
+ r'^(?P<locale>[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*|\*)(;q=(?P<weight>[01]\.\d{0,3}))?$')
MAX_ACCEPTED_LANGS = 10
@lru_cache()
self.assertStatus(200)
logger.info(self.body)
self.assertIn('<html lang="en">', self.body.decode('utf-8'))
+
+ @mock.patch(FakeFsMixin.builtins_open, new=FakeFsMixin.f_open)
+ @mock.patch('os.stat', new=FakeFsMixin.f_os.stat)
+ @mock.patch('os.listdir', new=FakeFsMixin.f_os.listdir)
+ def test_home_multiple_subtags_lang(self):
+ self._get('/', headers=[('Accept-Language', 'zh-Hans-CN')])
+ self.assertStatus(200)