GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pin HTTP/RTSP version + method normalization to Locale.US · netty/netty@64c47e0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src
    • main/java/io/netty/handler/codec
      • http
        • HttpVersion.java
      • rtsp
        • RtspMethods.java
        • RtspVersions.java
    • test/java/io/netty/handler/codec
      • http
        • HttpVersionLocaleTest.java
      • rtsp
        • RtspMethodsTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import io.netty.util.CharsetUtil;
2020
import io.netty.util.internal.ObjectUtil;
2121

22+
import java.util.Locale;
23+
2224
import static io.netty.util.internal.ObjectUtil.checkNonEmptyAfterTrim;
2325
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
2426

@@ -119,7 +121,10 @@ public HttpVersion(String text, boolean keepAliveDefault) {
119121
}
120122

121123
HttpVersion(String text, boolean strict, boolean keepAliveDefault) {
122-
text = checkNonEmptyAfterTrim(text, "text").toUpperCase();
124+
// toUpperCase() without an explicit Locale uses the JVM default. In Turkish locale
125+
// (tr_TR) 'i' uppercases to 'İ' (U+0130), which would corrupt protocol strings such
126+
// as "icap/1.0" or any custom HTTP-derived scheme that contains a lowercase 'i'.
127+
text = checkNonEmptyAfterTrim(text, "text").toUpperCase(Locale.US);
123128

124129
if (strict) {
125130
// Only single digit major / minor version is allowed.
@@ -197,7 +202,9 @@ public HttpVersion(
197202
private HttpVersion(
198203
String protocolName, int majorVersion, int minorVersion,
199204
boolean keepAliveDefault, boolean bytes) {
200-
protocolName = checkNonEmptyAfterTrim(protocolName, "protocolName").toUpperCase();
205+
// See the comment in the (text, strict, keepAliveDefault) constructor for why this needs
206+
// an explicit Locale.US: avoids the Turkish-locale 'i' -> 'İ' corruption.
207+
protocolName = checkNonEmptyAfterTrim(protocolName, "protocolName").toUpperCase(Locale.US);
201208

202209
for (int i = 0; i < protocolName.length(); i ++) {
203210
if (Character.isISOControl(protocolName.charAt(i)) ||
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspMethods.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspMethods.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.netty.handler.codec.http.HttpMethod;
2121

2222
import java.util.HashMap;
23+
import java.util.Locale;
2324
import java.util.Map;
2425

2526
/**
@@ -119,7 +120,10 @@ public final class RtspMethods {
119120
* will be returned. Otherwise, a new instance will be returned.
120121
*/
121122
public static HttpMethod valueOf(String name) {
122-
name = checkNonEmptyAfterTrim(name, "name").toUpperCase();
123+
// RFC 2326 RTSP method names are ASCII tokens. toUpperCase() without an explicit Locale
124+
// uses the JVM default, which in Turkish (tr_TR) maps 'i' to 'İ' (U+0130) and breaks the
125+
// lookup of methods such as "describe" or "redirect" against the cached uppercase keys.
126+
name = checkNonEmptyAfterTrim(name, "name").toUpperCase(Locale.US);
123127
HttpMethod result = methodMap.get(name);
124128
if (result != null) {
125129
return result;
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspVersions.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspVersions.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import io.netty.handler.codec.http.HttpVersion;
1919
import io.netty.util.internal.ObjectUtil;
2020

21+
import java.util.Locale;
22+
2123
/**
2224
* The version of RTSP.
2325
*/
@@ -37,7 +39,9 @@ public final class RtspVersions {
3739
public static HttpVersion valueOf(String text) {
3840
ObjectUtil.checkNotNull(text, "text");
3941

40-
text = text.trim().toUpperCase();
42+
// toUpperCase() must specify Locale.US so the comparison against "RTSP/1.0" is not
43+
// affected by the JVM default locale (e.g. Turkish, where 'i' uppercases to 'İ').
44+
text = text.trim().toUpperCase(Locale.US);
4145
if ("RTSP/1.0".equals(text)) {
4246
return RTSP_1_0;
4347
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpVersionLocaleTest.java‎

Copy file name to clipboard
+69Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.handler.codec.http;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import java.util.Locale;
22+
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
26+
/**
27+
* Tests that exercise {@link HttpVersion} parsing with the JVM-default Locale flipped to a value
28+
* that exposes the Turkish dotted-I problem (U+0130). {@link Locale#setDefault} is process-global
29+
* mutable state, so this class is marked {@link Isolated} to keep it from leaking into the rest
30+
* of the codec-http suite, which runs in concurrent mode
31+
* ({@code junit.jupiter.execution.parallel.mode.default = concurrent}).
32+
*/
33+
@Isolated("Mutates Locale.getDefault() which is JVM-global state.")
34+
class HttpVersionLocaleTest {
35+
36+
@Test
37+
void testLowercaseIotaProtocolNameUnderTurkishLocale() {
38+
// Turkish locale maps 'i' -> 'İ' (U+0130) under the JVM-default toUpperCase().
39+
// The constructor must use Locale.US so an HTTP-derived protocol name like "icap"
40+
// round-trips to the ASCII "ICAP" instead of being corrupted to "İCAP".
41+
Locale original = Locale.getDefault();
42+
try {
43+
Locale.setDefault(new Locale("tr", "TR"));
44+
HttpVersion version = HttpVersion.valueOf("icap/1.0");
45+
assertEquals("ICAP", version.protocolName());
46+
for (int i = 0; i < version.protocolName().length(); i++) {
47+
assertTrue(version.protocolName().charAt(i) < 0x80,
48+
"protocolName must remain ASCII regardless of JVM default locale");
49+
}
50+
assertEquals("ICAP/1.0", version.text());
51+
} finally {
52+
Locale.setDefault(original);
53+
}
54+
}
55+
56+
@Test
57+
void testProtocolNameConstructorUnderTurkishLocale() {
58+
// Same Locale.US guarantee for the (protocolName, major, minor, ...) constructor.
59+
Locale original = Locale.getDefault();
60+
try {
61+
Locale.setDefault(new Locale("tr", "TR"));
62+
HttpVersion version = new HttpVersion("icap", 1, 0, true);
63+
assertEquals("ICAP", version.protocolName());
64+
assertEquals("ICAP/1.0", version.text());
65+
} finally {
66+
Locale.setDefault(original);
67+
}
68+
}
69+
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/rtsp/RtspMethodsTest.java‎

Copy file name to clipboard
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.handler.codec.rtsp;
17+
18+
import io.netty.handler.codec.http.HttpMethod;
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.parallel.Isolated;
21+
22+
import java.util.Locale;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertSame;
26+
27+
@Isolated("valueOfNormalizesLowercaseInputUnderTurkishLocale flips the JVM-default Locale, "
28+
+ "which is process-global state, so the class must not run alongside the rest of the "
29+
+ "codec-http suite (junit.jupiter.execution.parallel.mode.default = concurrent).")
30+
class RtspMethodsTest {
31+
32+
@Test
33+
void valueOfReturnsCachedInstanceForUppercaseName() {
34+
assertSame(RtspMethods.DESCRIBE, RtspMethods.valueOf("DESCRIBE"));
35+
assertSame(RtspMethods.SETUP, RtspMethods.valueOf("SETUP"));
36+
assertSame(RtspMethods.GET_PARAMETER, RtspMethods.valueOf("GET_PARAMETER"));
37+
}
38+
39+
@Test
40+
void valueOfNormalizesLowercaseInputUnderUsLocale() {
41+
assertSame(RtspMethods.DESCRIBE, RtspMethods.valueOf("describe"));
42+
assertSame(RtspMethods.PLAY, RtspMethods.valueOf("play"));
43+
assertSame(RtspMethods.REDIRECT, RtspMethods.valueOf("redirect"));
44+
}
45+
46+
@Test
47+
void valueOfNormalizesLowercaseInputUnderTurkishLocale() {
48+
// In Turkish locale (tr_TR), 'i' uppercases to 'İ' (U+0130) under the JVM default.
49+
// RtspMethods.valueOf must pin Locale.US so RTSP method names that contain 'i' such as
50+
// "describe" or "redirect" continue to resolve to the cached uppercase entries.
51+
Locale original = Locale.getDefault();
52+
try {
53+
Locale.setDefault(new Locale("tr", "TR"));
54+
HttpMethod describe = RtspMethods.valueOf("describe");
55+
HttpMethod redirect = RtspMethods.valueOf("redirect");
56+
assertSame(RtspMethods.DESCRIBE, describe);
57+
assertSame(RtspMethods.REDIRECT, redirect);
58+
// Sanity-check: with the locale-default toUpperCase the names would have contained
59+
// U+0130 instead of plain 'I'. Asserting the resolved names round-trip to ASCII
60+
// pins down that the fix is taking effect.
61+
assertEquals("DESCRIBE", describe.name());
62+
assertEquals("REDIRECT", redirect.name());
63+
} finally {
64+
Locale.setDefault(original);
65+
}
66+
}
67+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.