tinganho / node-accept-language

BCP47 language negotiation
MIT License
85 stars 15 forks source link

Accept-Language: * causes error #17

Closed d0b1010r closed 8 years ago

d0b1010r commented 8 years ago

If a client uses a star (*) in the Accept-Language header accept-language fails with error

TypeError: Cannot read property 'langtag' of null
    at AcceptLanguage.parse (/Users/davidlanger/repos/casavi/node_modules/accept-language/Build/Source/AcceptLanguage.js:51:64)
    at AcceptLanguage.get (/Users/davidlanger/repos/casavi/node_modules/accept-language/Build/Source/AcceptLanguage.js:36:21)
    at /Users/davidlanger/repos/casavi/node_modules/express-request-language/index.js:112:66

An example request would be:

curl -H "accept-language: *" http://localhost

But any combination that uses a star fails, because bcp47 fails matching anything, so returns null. This then causes the error. It also fails if anything else than a known string is used (ie. Accept-Header: X). This should probably not throw an error.

Using * is valid by w3c