i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

Get language is broken when locale part of language code is lowercase #171

Closed radeno closed 5 years ago

radeno commented 5 years ago

By this commit https://github.com/i18next/i18next-express-middleware/pull/169

there is bug when accept language is set in whole lowercase characters. For example in Safari browser is accept language sent as Accept-Language: en-us in chrome: accept-language: en-US,en;q=0.9,sk;q=0.8

Lannguage code instead en is returned as en-

So regex /(([a-z]{2})-?([A-Z]{2})?)\s*;?\s*(q=([0-9.]+))?/g fails when is language passed as en-us because it excepts uppercase characters.

Example here: https://regex101.com/r/2mmR4w/2

Regex should be defined with insensitive flag i:

/(([a-z]{2})-?([A-Z]{2})?)\s*;?\s*(q=([0-9.]+))?/gi
jamuhl commented 5 years ago

Feel free to provide a PR if like to see this landed soon - else i will add it next time i work on this project.