[jdk17u-dev] RFR: 8305763: Parsing a URI with an underscore goes through a silent exception, negatively impacting performance
Mike Lothian
duke at openjdk.org
Thu Jul 11 13:23:08 UTC 2024
On Tue, 13 Jun 2023 16:58:19 GMT, Dhamoder Nalla <dhanalla at openjdk.org> wrote:
> Backport https://github.com/openjdk/jdk/pull/13430
I'm seeing a "URI Syntax Exception: Illegal character in hostname at index 10:" in a PUT after getting a successful bearer token in a previous call the url start https://2t_
Do we need something along the lines of:
diff --git a/src/java.base/share/classes/java/net/URI.java b/src/java.base/share/classes/java/net/URI.java
index 644fc05bdc1..2b6996ee12a 100644
--- a/src/java.base/share/classes/java/net/URI.java
+++ b/src/java.base/share/classes/java/net/URI.java
@@ -2717,6 +2717,10 @@ public final class URI
private static final long L_DASH = 0x200000000000L; // lowMask("-");
private static final long H_DASH = 0x0L; // highMask("-");
+ // Underscore, for use in hostnames
+ private static final long L_UNDERSCORE = 0L; // lowMask("_");
+ private static final long H_UNDERSCORE = 0x80000000; // highMask("_");
+
// Dot, for use in hostnames
private static final long L_DOT = 0x400000000000L; // lowMask(".");
private static final long H_DOT = 0x0L; // highMask(".");
@@ -3511,7 +3515,7 @@ public final class URI
l = p;
if (q > p) {
p = q;
- q = scan(p, n, L_ALPHANUM | L_DASH, H_ALPHANUM | H_DASH);
+ q = scan(p, n, L_ALPHANUM | L_DASH | L_UNDERSCORE, H_ALPHANUM | H_DASH | H_UNDERSCORE);
if (q > p) {
if (input.charAt(q - 1) == '-')
fail("Illegal character in hostname", q - 1);
-------------
PR Comment: https://git.openjdk.org/jdk17u-dev/pull/1428#issuecomment-2222848978
More information about the jdk-updates-dev
mailing list