This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 011724a02d Treat the weight parameter name as case-insensitive (#1144)
011724a02d is described below

commit 011724a02d34c669cd3ebbdee3b6f0f62beeaf79
Author: Arturo Bernal <[email protected]>
AuthorDate: Fri Nov 13 13:01:50 2026 +0100

    Treat the weight parameter name as case-insensitive (#1144)
    
    RFC 9110, section 5.6.6 states that parameter names are case-insensitive
    and the weight is defined as the ABNF string "q=", which is also
    case-insensitive. A weight such as "gzip;Q=0" was treated as malformed
    in Accept-Encoding and Accept-Language, so the entry was dropped and a
    "*" entry could re-enable a coding the client had excluded, and TE kept
    "Q" as an ordinary parameter with a quality of 1. Accept an upper case
    "Q".
---
 java/org/apache/tomcat/util/http/parser/HttpParser.java   |  2 +-
 java/org/apache/tomcat/util/http/parser/TE.java           |  4 +++-
 .../tomcat/util/http/parser/TestAcceptEncoding.java       | 15 +++++++++++++++
 .../tomcat/util/http/parser/TestAcceptLanguage.java       | 10 ++++++++++
 test/org/apache/tomcat/util/http/parser/TestTE.java       | 11 +++++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java 
b/java/org/apache/tomcat/util/http/parser/HttpParser.java
index 45f63f7b0f..b0429a0688 100644
--- a/java/org/apache/tomcat/util/http/parser/HttpParser.java
+++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java
@@ -834,7 +834,7 @@ public class HttpParser {
         if (c == -1 || c == delimiter) {
             // No q value just whitespace
             return 1;
-        } else if (c != 'q') {
+        } else if (c != 'q' && c != 'Q') {
             // Malformed. Use quality of -1 so it is dropped.
             skipUntil(input, c, delimiter);
             return -1;
diff --git a/java/org/apache/tomcat/util/http/parser/TE.java 
b/java/org/apache/tomcat/util/http/parser/TE.java
index 5e027994c6..aab3f5787a 100644
--- a/java/org/apache/tomcat/util/http/parser/TE.java
+++ b/java/org/apache/tomcat/util/http/parser/TE.java
@@ -21,6 +21,7 @@ import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -118,7 +119,8 @@ public class TE {
                     value = HttpParser.readTokenOrQuotedString(input, true);
                 }
                 if (name != null && value != null) {
-                    parameters.put(name, value);
+                    // Parameter names are case-insensitive (RFC 9110, section 
5.6.6)
+                    parameters.put(name.toLowerCase(Locale.ENGLISH), value);
                 }
             }
 
diff --git a/test/org/apache/tomcat/util/http/parser/TestAcceptEncoding.java 
b/test/org/apache/tomcat/util/http/parser/TestAcceptEncoding.java
index a127989801..23672d57f5 100644
--- a/test/org/apache/tomcat/util/http/parser/TestAcceptEncoding.java
+++ b/test/org/apache/tomcat/util/http/parser/TestAcceptEncoding.java
@@ -209,6 +209,21 @@ public class TestAcceptEncoding {
     }
 
 
+    /*
+     * RFC 9110, section 12.4.2: the weight is "q=" qvalue. ABNF strings are 
case-insensitive (RFC 5234, section 2.3) and
+     * parameter names are case-insensitive (RFC 9110, section 5.6.6).
+     */
+    @Test
+    public void testWeightNameCaseInsensitive() throws Exception {
+        List<AcceptEncoding> actual = parse("gzip;Q=0.5, br;Q=0, *;Q=1");
+
+        Assert.assertEquals(3, actual.size());
+        assertEntry(actual.get(0), "gzip", 0.5);
+        assertEntry(actual.get(1), "br", 0);
+        assertEntry(actual.get(2), "*", 1);
+    }
+
+
     private static List<AcceptEncoding> parse(String header) throws 
IOException {
         return AcceptEncoding.parse(new StringReader(header));
     }
diff --git a/test/org/apache/tomcat/util/http/parser/TestAcceptLanguage.java 
b/test/org/apache/tomcat/util/http/parser/TestAcceptLanguage.java
index 766627df3e..81cf18e8ab 100644
--- a/test/org/apache/tomcat/util/http/parser/TestAcceptLanguage.java
+++ b/test/org/apache/tomcat/util/http/parser/TestAcceptLanguage.java
@@ -50,6 +50,16 @@ public class TestAcceptLanguage {
         Assert.assertEquals(Q1_000, actual.get(0).getQuality(), 0.0001);
     }
 
+    @Test
+    public void testWeightNameCaseInsensitive() throws Exception {
+        // RFC 9110, section 5.6.6: parameter names are case-insensitive
+        List<AcceptLanguage> actual = AcceptLanguage.parse(new 
StringReader("en-gb;Q=0.5"));
+
+        Assert.assertEquals(1, actual.size());
+        Assert.assertEquals(L_EN_GB, actual.get(0).getLocale());
+        Assert.assertEquals(Q0_500, actual.get(0).getQuality(), 0.0001);
+    }
+
     @Test
     public void testSingle03() throws Exception {
         List<AcceptLanguage> actual = AcceptLanguage.parse(new 
StringReader("en-gb;"));
diff --git a/test/org/apache/tomcat/util/http/parser/TestTE.java 
b/test/org/apache/tomcat/util/http/parser/TestTE.java
index 59d6ab2f78..8eda474e85 100644
--- a/test/org/apache/tomcat/util/http/parser/TestTE.java
+++ b/test/org/apache/tomcat/util/http/parser/TestTE.java
@@ -47,6 +47,17 @@ public class TestTE {
         Assert.assertEquals(Q0_500, actual.get(0).getQuality(), 0.0001);
     }
 
+    @Test
+    public void testWeightNameCaseInsensitive() throws Exception {
+        // RFC 9110, section 5.6.6: parameter names are case-insensitive
+        List<TE> actual = TE.parse(new StringReader("gzip;Q=0.5, 
deflate;Q=0"));
+
+        Assert.assertEquals(1, actual.size());
+        Assert.assertEquals("gzip", actual.get(0).getEncoding());
+        Assert.assertEquals(Q0_500, actual.get(0).getQuality(), 0.0001);
+        Assert.assertTrue(actual.get(0).getParameters().isEmpty());
+    }
+
     @Test
     public void testComplexTE2() throws Exception {
         List<TE> actual = TE.parse(new StringReader("gzip;q=0.5, 
something;q=0.05"));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to