Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept-Language header not parsed correctly for language subtags, variants, extension and private subtags #36227

Open
nderwin opened this issue Oct 1, 2023 · 1 comment · May be fixed by #36228
Labels
kind/bug Something isn't working

Comments

@nderwin
Copy link
Contributor

nderwin commented Oct 1, 2023

Describe the bug

When using an Accept-Language header for HTTP requests that contains more than simple language or language-country forms, the parsed Locale does not correctly reflect the given language tag as defined in https://www.rfc-editor.org/rfc/rfc9110#section-12.5.4.

Other examples of complex tags can be found in https://www.w3.org/International/articles/language-tags/.

Expected behavior

Language tags are parsed into a Locale that correctly reflects the given data; examples (not sure if zh-yue being turned into yue or ar-afb being turned into afb are correct, but that's what java.util.Locale turns it into):

Accept-Language: en
         Parsed: en

Accept-Language: ast
         Parsed: ast

Accept-Language: zh-yue
         Parsed: yue

Accept-Language: ar-afb
         Parsed: afb

Accept-Language: zh-Hans
         Parsed: zh-Hans

Accept-Language: az-Latn
         Parsed: az-Latn

Accept-Language: en-GB
         Parsed: en-GB

Accept-Language: es-005
         Parsed: es-005

Accept-Language: zh-Hant-HK
         Parsed: zh-Hant-HK

Accept-Language: sl-nedis
         Parsed: sl-nedis

Accept-Language: sl-IT-nedis
         Parsed: sl-IT-nedis

Accept-Language: de-CH-1901
         Parsed: de-CH-1901

Accept-Language: de-DE-u-co-phonebk
         Parsed: de-DE-u-co-phonebk

Accept-Language: en-US-x-twain
         Parsed: en-US-x-twain

Actual behavior

Simpler language tags are parsed correctly, but some of the more complex ones are not:

Accept-Language: en
         Parsed: en

Accept-Language: ast
         Parsed: ast

Accept-Language: zh-yue
         Parsed: zh

Accept-Language: ar-afb
         Parsed: ar

Accept-Language: zh-Hans
         Parsed: zh

Accept-Language: az-Latn
         Parsed: az

Accept-Language: en-GB
         Parsed: en-GB

Accept-Language: es-005
         Parsed: es-005

Accept-Language: zh-Hant-HK
         Parsed: zh-x-lvariant-HK

Accept-Language: sl-nedis
         Parsed: sl

Accept-Language: sl-IT-nedis
         Parsed: sl-IT-nedis

Accept-Language: de-CH-1901
         Parsed: de-CH-1901

Accept-Language: de-DE-u-co-phonebk
         Parsed: de-DE-x-lvariant-u

Accept-Language: en-US-x-twain
         Parsed: en-US-x-lvariant-x

How to Reproduce?

i18n-with-quarkus-reactive.zip

  1. run the application with ./mvnw clean compile quarkus:dev
  2. either use the included tests.sh script to run some curl commands, or craft your own with an Accept-Language header for the URL http://localhost:8080/hello
  3. note the response to see if the parsed Locale produces the same language tag as the given header

Output of uname -a or ver

Linux laverne 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.8.1" 2023-08-24

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.4.1

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.3 (21122926829f1ead511c958d89bd2f672198ae9f)

Additional information

No response

@nderwin nderwin added the kind/bug Something isn't working label Oct 1, 2023
nderwin added a commit to nderwin-forks/quarkus that referenced this issue Oct 1, 2023
…header.

This is a fix for quarkusio#36227.
Signed-off-by:Nathan Erwin <nathan.d.erwin@gmail.com>
nderwin added a commit to nderwin-forks/quarkus that referenced this issue Oct 2, 2023
…header

* added some tests with various language tag scenarios
* Fixes quarkusio#36227

Signed-off-by:Nathan Erwin <nathan.d.erwin@gmail.com>
@jamezp
Copy link
Contributor

jamezp commented Oct 6, 2023

FYI I need to look into this for RESTEasy because the change causes TCK failures.

nderwin added a commit to nderwin-forks/quarkus that referenced this issue Mar 18, 2024
…header

* added some tests with various language tag scenarios
* Fixes quarkusio#36227

Signed-off-by:Nathan Erwin <nathan.d.erwin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants