This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 7a342440ce Treat the weight parameter name as case-insensitive (#1144)
7a342440ce is described below
commit 7a342440cef94433a86945ee34b9f0405dce3278
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 +++++++++++
webapps/docs/changelog.xml | 5 +++++
6 files changed, 45 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 ed5f3ab9e1..92f773ff92 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"));
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 8adbbe5aa5..2c011c8328 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -138,6 +138,11 @@
Ignore empty list elements when parsing the HTTP Upgrade header. Pull
request <pr>1143</pr> provided by Arturo Bernal. (markt)
</fix>
+ <fix>
+ When parsing HTTP headers, treat the name of the weight parameter (e.g.
+ in the <code>Accept-Language</code> header) as case insensitive. Pull
+ request <pr>1144</pr> provided by Arturo Bernal. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]