From 05e99db466e7ef5c26f089db772a21cb2ca62e93 Mon Sep 17 00:00:00 2001 From: Darragh Clarke Date: Mon, 22 May 2023 10:53:59 +0000 Subject: [PATCH] 7065228: To interpret case-insensitive string locale independently Reviewed-by: dfuchs, naoto, djelinski, jpai, michaelm --- .../share/classes/java/net/HttpCookie.java | 12 ++++++------ .../classes/java/net/InetSocketAddress.java | 3 ++- .../classes/java/net/SocketPermission.java | 11 ++++++----- .../share/classes/java/net/URLConnection.java | 3 ++- .../classes/java/net/URLStreamHandler.java | 5 +++-- .../classes/sun/net/ftp/FtpDirEntry.java | 7 ++++--- .../sun/net/spi/DefaultProxySelector.java | 5 +++-- .../share/classes/sun/net/util/URLUtil.java | 9 +++++---- .../classes/sun/net/www/HeaderParser.java | 13 +++++++------ .../share/classes/sun/net/www/MimeEntry.java | 7 ++++--- .../share/classes/sun/net/www/MimeTable.java | 5 +++-- .../classes/sun/net/www/URLConnection.java | 6 +++--- .../protocol/http/AuthenticationHeader.java | 5 +++-- .../www/protocol/http/AuthenticationInfo.java | 19 ++++++++++--------- .../protocol/http/DigestAuthentication.java | 4 ++-- .../www/protocol/http/HttpURLConnection.java | 4 ++-- .../http/NegotiateAuthentication.java | 3 ++- .../protocol/http/spnego/NegotiatorImpl.java | 5 +++-- .../sun/net/httpserver/ContextList.java | 4 ++-- .../sun/net/httpserver/HttpContextImpl.java | 4 ++-- 20 files changed, 74 insertions(+), 60 deletions(-) diff --git a/src/java.base/share/classes/java/net/HttpCookie.java b/src/java.base/share/classes/java/net/HttpCookie.java index bc6c00bd13b..871b885c085 100644 --- a/src/java.base/share/classes/java/net/HttpCookie.java +++ b/src/java.base/share/classes/java/net/HttpCookie.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -370,7 +370,7 @@ public final class HttpCookie implements Cloneable { */ public void setDomain(String pattern) { if (pattern != null) - domain = pattern.toLowerCase(); + domain = pattern.toLowerCase(Locale.ROOT); else domain = pattern; } @@ -743,8 +743,8 @@ public final class HttpCookie implements Cloneable { */ @Override public int hashCode() { - int h1 = name.toLowerCase().hashCode(); - int h2 = (domain!=null) ? domain.toLowerCase().hashCode() : 0; + int h1 = name.toLowerCase(Locale.ROOT).hashCode(); + int h2 = (domain!=null) ? domain.toLowerCase(Locale.ROOT).hashCode() : 0; int h3 = (path!=null) ? path.hashCode() : 0; return h1 + h2 + h3; @@ -977,7 +977,7 @@ public final class HttpCookie implements Cloneable { // strip off the surrounding "-sign if there's any attrValue = stripOffSurroundingQuote(attrValue); - CookieAttributeAssignor assignor = assignors.get(attrName.toLowerCase()); + CookieAttributeAssignor assignor = assignors.get(attrName.toLowerCase(Locale.ROOT)); if (assignor != null) { assignor.assign(cookie, attrName, attrValue); } else { @@ -1079,7 +1079,7 @@ public final class HttpCookie implements Cloneable { private static int guessCookieVersion(String header) { int version = 0; - header = header.toLowerCase(); + header = header.toLowerCase(Locale.ROOT); if (header.contains("expires=")) { // only netscape cookie using 'expires' version = 0; diff --git a/src/java.base/share/classes/java/net/InetSocketAddress.java b/src/java.base/share/classes/java/net/InetSocketAddress.java index 08a4319dbf9..5acfbcfa37c 100644 --- a/src/java.base/share/classes/java/net/InetSocketAddress.java +++ b/src/java.base/share/classes/java/net/InetSocketAddress.java @@ -30,6 +30,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamException; import java.io.ObjectStreamField; +import java.util.Locale; /** * @@ -137,7 +138,7 @@ public class InetSocketAddress if (addr != null) return addr.hashCode() + port; if (hostname != null) - return hostname.toLowerCase().hashCode() + port; + return hostname.toLowerCase(Locale.ROOT).hashCode() + port; return port; } } diff --git a/src/java.base/share/classes/java/net/SocketPermission.java b/src/java.base/share/classes/java/net/SocketPermission.java index 54214b7af03..2027676c36a 100644 --- a/src/java.base/share/classes/java/net/SocketPermission.java +++ b/src/java.base/share/classes/java/net/SocketPermission.java @@ -36,6 +36,7 @@ import java.security.PermissionCollection; import java.security.PrivilegedAction; import java.util.Collections; import java.util.Enumeration; +import java.util.Locale; import java.util.Map; import java.util.StringJoiner; import java.util.StringTokenizer; @@ -460,7 +461,7 @@ public final class SocketPermission extends Permission if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { - cname = host.substring(1).toLowerCase(); + cname = host.substring(1).toLowerCase(Locale.ROOT); } else { throw new IllegalArgumentException("invalid host wildcard specification"); @@ -670,10 +671,10 @@ public final class SocketPermission extends Permission // we have to do this check, otherwise we might not // get the fully qualified domain name if (init_with_ip) { - cname = addresses[0].getHostName(false).toLowerCase(); + cname = addresses[0].getHostName(false).toLowerCase(Locale.ROOT); } else { cname = InetAddress.getByName(addresses[0].getHostAddress()). - getHostName(false).toLowerCase(); + getHostName(false).toLowerCase(Locale.ROOT); } } catch (UnknownHostException uhe) { invalid = true; @@ -696,8 +697,8 @@ public final class SocketPermission extends Permission } private boolean match(String cname, String hname) { - String a = checkForIDN(cname.toLowerCase()); - String b = checkForIDN(hname.toLowerCase()); + String a = checkForIDN(cname.toLowerCase(Locale.ROOT)); + String b = checkForIDN(hname.toLowerCase(Locale.ROOT)); if (a.startsWith(b) && ((a.length() == b.length()) || (a.charAt(b.length()) == '.'))) { return true; diff --git a/src/java.base/share/classes/java/net/URLConnection.java b/src/java.base/share/classes/java/net/URLConnection.java index cebf5428e7e..3ffcdba1848 100644 --- a/src/java.base/share/classes/java/net/URLConnection.java +++ b/src/java.base/share/classes/java/net/URLConnection.java @@ -38,6 +38,7 @@ import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.StringTokenizer; import java.util.Collections; +import java.util.Locale; import java.util.Map; import java.util.List; import java.security.Permission; @@ -1454,7 +1455,7 @@ public abstract class URLConnection { */ private String typeToPackageName(String contentType) { // make sure we canonicalize the class name: all lower case - contentType = contentType.toLowerCase(); + contentType = contentType.toLowerCase(Locale.ROOT); int len = contentType.length(); char nm[] = new char[len]; contentType.getChars(0, len, nm, 0); diff --git a/src/java.base/share/classes/java/net/URLStreamHandler.java b/src/java.base/share/classes/java/net/URLStreamHandler.java index 58ee34807af..1400741b2bb 100644 --- a/src/java.base/share/classes/java/net/URLStreamHandler.java +++ b/src/java.base/share/classes/java/net/URLStreamHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.net; import java.io.IOException; +import java.util.Locale; import java.util.Objects; import sun.net.util.IPAddressUtil; @@ -374,7 +375,7 @@ public abstract class URLStreamHandler { } else { String host = u.getHost(); if (host != null) - h += host.toLowerCase().hashCode(); + h += host.toLowerCase(Locale.ROOT).hashCode(); } // Generate the file part. diff --git a/src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java b/src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java index 01ad1ceae35..b999fe5e189 100644 --- a/src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java +++ b/src/java.base/share/classes/sun/net/ftp/FtpDirEntry.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package sun.net.ftp; import java.util.Date; import java.util.HashMap; +import java.util.Locale; /** * A {@code FtpDirEntry} is a class agregating all the information that the FTP client @@ -273,7 +274,7 @@ public class FtpDirEntry { * @return this {@code FtpDirEntry} */ public FtpDirEntry addFact(String fact, String value) { - facts.put(fact.toLowerCase(), value); + facts.put(fact.toLowerCase(Locale.ROOT), value); return this; } @@ -285,7 +286,7 @@ public class FtpDirEntry { * provided by the server. */ public String getFact(String fact) { - return facts.get(fact.toLowerCase()); + return facts.get(fact.toLowerCase(Locale.ROOT)); } /** diff --git a/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java b/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java index cfe5c80fe28..fcc4a4862d6 100644 --- a/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java +++ b/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,7 @@ import java.util.List; import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Locale; import java.util.StringJoiner; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -205,7 +206,7 @@ public class DefaultProxySelector extends ProxySelector { */ final String proto = protocol; final NonProxyInfo nprop = pinfo; - final String urlhost = host.toLowerCase(); + final String urlhost = host.toLowerCase(Locale.ROOT); /** * This is one big doPrivileged call, but we're trying to optimize diff --git a/src/java.base/share/classes/sun/net/util/URLUtil.java b/src/java.base/share/classes/sun/net/util/URLUtil.java index 6d80825e901..9eb04ce4151 100644 --- a/src/java.base/share/classes/sun/net/util/URLUtil.java +++ b/src/java.base/share/classes/sun/net/util/URLUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.URL; import java.net.URLPermission; import java.security.Permission; +import java.util.Locale; /** * URL Utility class. @@ -55,7 +56,7 @@ public class URLUtil { * use identity tests for speed */ if (protocol != "file" && protocol != "jrt" && protocol != "jar") { - protocol = protocol.toLowerCase(); + protocol = protocol.toLowerCase(Locale.ROOT); } strForm.append(protocol); strForm.append("://"); @@ -65,7 +66,7 @@ public class URLUtil { if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ if (!host.isEmpty()) { - strForm.append(host.toLowerCase()); + strForm.append(host.toLowerCase(Locale.ROOT)); } int port = url.getPort(); @@ -88,7 +89,7 @@ public class URLUtil { } public static Permission getConnectPermission(URL url) throws IOException { - String urlStringLowerCase = url.toString().toLowerCase(); + String urlStringLowerCase = url.toString().toLowerCase(Locale.ROOT); if (urlStringLowerCase.startsWith("http:") || urlStringLowerCase.startsWith("https:")) { return getURLConnectPermission(url); } else if (urlStringLowerCase.startsWith("jar:http:") || urlStringLowerCase.startsWith("jar:https:")) { diff --git a/src/java.base/share/classes/sun/net/www/HeaderParser.java b/src/java.base/share/classes/sun/net/www/HeaderParser.java index e6d7435a458..1efa6a79302 100644 --- a/src/java.base/share/classes/sun/net/www/HeaderParser.java +++ b/src/java.base/share/classes/sun/net/www/HeaderParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package sun.net.www; import java.util.Iterator; +import java.util.Locale; import java.util.OptionalInt; /* This is useful for the nightmare of parsing multi-part HTTP/RFC822 headers @@ -94,7 +95,7 @@ public class HeaderParser { while (end < len) { char c = ca[end]; if ((c == '=') && !inQuote) { // end of a key - tab[i][0] = new String(ca, beg, end-beg).toLowerCase(); + tab[i][0] = new String(ca, beg, end-beg).toLowerCase(Locale.ROOT); inKey = false; end++; beg = end; @@ -117,7 +118,7 @@ public class HeaderParser { end++; continue; } else if (inKey) { - tab[i++][0] = (new String(ca, beg, end-beg)).toLowerCase(); + tab[i++][0] = (new String(ca, beg, end-beg)).toLowerCase(Locale.ROOT); } else { tab[i++][1] = (new String(ca, beg, end-beg)); } @@ -145,7 +146,7 @@ public class HeaderParser { tab[i++][1] = (new String(ca, beg, end-beg+1)); } } else { - tab[i++][0] = (new String(ca, beg, end-beg+1)).toLowerCase(); + tab[i++][0] = (new String(ca, beg, end-beg+1)).toLowerCase(Locale.ROOT); } } else if (end == beg) { if (!inKey) { @@ -155,7 +156,7 @@ public class HeaderParser { tab[i++][1] = String.valueOf(ca[end]); } } else { - tab[i++][0] = String.valueOf(ca[end]).toLowerCase(); + tab[i++][0] = String.valueOf(ca[end]).toLowerCase(Locale.ROOT); } } nkeys=i; @@ -182,7 +183,7 @@ public class HeaderParser { public String findValue(String k, String Default) { if (k == null) return Default; - k = k.toLowerCase(); + k = k.toLowerCase(Locale.ROOT); for (int i = 0; i < asize; ++i) { if (tab[i][0] == null) { return Default; diff --git a/src/java.base/share/classes/sun/net/www/MimeEntry.java b/src/java.base/share/classes/sun/net/www/MimeEntry.java index 3422b58e1bc..9e8a3861366 100644 --- a/src/java.base/share/classes/sun/net/www/MimeEntry.java +++ b/src/java.base/share/classes/sun/net/www/MimeEntry.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ package sun.net.www; import java.io.*; +import java.util.Locale; import java.util.StringJoiner; import java.util.StringTokenizer; @@ -66,7 +67,7 @@ public class MimeEntry implements Cloneable { MimeEntry(String typeName, int action, String command, String imageFileName, String fileExtensions[]) { - this.typeName = typeName.toLowerCase(); + this.typeName = typeName.toLowerCase(Locale.ROOT); this.action = action; this.command = command; this.imageFileName = imageFileName; @@ -81,7 +82,7 @@ public class MimeEntry implements Cloneable { } public synchronized void setType(String type) { - typeName = type.toLowerCase(); + typeName = type.toLowerCase(Locale.ROOT); } public synchronized int getAction() { diff --git a/src/java.base/share/classes/sun/net/www/MimeTable.java b/src/java.base/share/classes/sun/net/www/MimeTable.java index 3d7f15ade6e..926fe7d60b3 100644 --- a/src/java.base/share/classes/sun/net/www/MimeTable.java +++ b/src/java.base/share/classes/sun/net/www/MimeTable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,7 @@ import java.io.InputStream; import java.io.IOException; import java.net.FileNameMap; import java.util.Enumeration; +import java.util.Locale; import java.util.Hashtable; import java.util.Properties; import java.util.StringTokenizer; @@ -164,7 +165,7 @@ public class MimeTable implements FileNameMap { String ext = ""; if (i != -1 && fname.charAt(i) == '.') { - ext = fname.substring(i).toLowerCase(); + ext = fname.substring(i).toLowerCase(Locale.ROOT); } return findByExt(ext); diff --git a/src/java.base/share/classes/sun/net/www/URLConnection.java b/src/java.base/share/classes/sun/net/www/URLConnection.java index b3af24c594b..6851367ad67 100644 --- a/src/java.base/share/classes/sun/net/www/URLConnection.java +++ b/src/java.base/share/classes/sun/net/www/URLConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -264,10 +264,10 @@ public abstract class URLConnection extends java.net.URLConnection { private static HashMap proxiedHosts = new HashMap<>(); public static synchronized void setProxiedHost(String host) { - proxiedHosts.put(host.toLowerCase(), null); + proxiedHosts.put(host.toLowerCase(Locale.ROOT), null); } public static synchronized boolean isProxiedHost(String host) { - return proxiedHosts.containsKey(host.toLowerCase()); + return proxiedHosts.containsKey(host.toLowerCase(Locale.ROOT)); } } diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java index dbfc04b7d59..bf237259e18 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ package sun.net.www.protocol.http; import java.util.Collections; import java.util.Iterator; +import java.util.Locale; import java.util.HashMap; import java.util.Set; @@ -106,7 +107,7 @@ public class AuthenticationHeader { // were used later. if (authPref != null) { - authPref = authPref.toLowerCase(); + authPref = authPref.toLowerCase(Locale.ROOT); if(authPref.equals("spnego") || authPref.equals("kerberos")) { authPref = "negotiate"; } diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java index 8134b994812..4a2b5b628c6 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java @@ -30,6 +30,7 @@ import java.io.ObjectInputStream; import java.net.PasswordAuthentication; import java.net.URL; import java.util.HashMap; +import java.util.Locale; import java.util.Objects; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; @@ -219,7 +220,7 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone this.type = type; this.authScheme = authScheme; this.protocol = ""; - this.host = host.toLowerCase(); + this.host = host.toLowerCase(Locale.ROOT); this.port = port; this.realm = realm; this.path = null; @@ -241,8 +242,8 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) { this.type = type; this.authScheme = authScheme; - this.protocol = url.getProtocol().toLowerCase(); - this.host = url.getHost().toLowerCase(); + this.protocol = url.getProtocol().toLowerCase(Locale.ROOT); + this.host = url.getHost().toLowerCase(Locale.ROOT); this.port = url.getPort(); if (this.port == -1) { this.port = url.getDefaultPort(); @@ -284,8 +285,8 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone if (port == -1) { port = url.getDefaultPort(); } - String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase() - + ":" + url.getHost().toLowerCase() + ":" + port; + String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase(Locale.ROOT) + + ":" + url.getHost().toLowerCase(Locale.ROOT) + ":" + port; return getAuth(key, url, cache); } @@ -301,8 +302,8 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone port = url.getDefaultPort(); } String key = SERVER_AUTHENTICATION + ":" + scheme + ":" - + url.getProtocol().toLowerCase() - + ":" + url.getHost().toLowerCase() + + url.getProtocol().toLowerCase(Locale.ROOT) + + ":" + url.getHost().toLowerCase(Locale.ROOT) + ":" + port + ":" + realm; return key; } @@ -336,7 +337,7 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone */ static AuthenticationInfo getProxyAuth(String host, int port, AuthCacheImpl acache) { Objects.requireNonNull(acache); - String key = PROXY_AUTHENTICATION + "::" + host.toLowerCase() + ":" + port; + String key = PROXY_AUTHENTICATION + "::" + host.toLowerCase(Locale.ROOT) + ":" + port; AuthenticationInfo result = (AuthenticationInfo) acache.get(key, null); return result; } @@ -348,7 +349,7 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone */ static String getProxyAuthKey(String host, int port, String realm, AuthScheme scheme) { String key = PROXY_AUTHENTICATION + ":" + scheme - + "::" + host.toLowerCase() + + "::" + host.toLowerCase(Locale.ROOT) + ":" + port + ":" + realm; return key; } diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java b/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java index 705c3d4976f..66e78c866b7 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/DigestAuthentication.java @@ -434,7 +434,7 @@ class DigestAuthentication extends AuthenticationInfo { // It really does need to start with an upper case letter // here. authMethod = Character.toUpperCase(authMethod.charAt(0)) - + authMethod.substring(1).toLowerCase(); + + authMethod.substring(1).toLowerCase(Locale.ROOT); } if (!setAlgorithmNames(p, params)) @@ -513,7 +513,7 @@ class DigestAuthentication extends AuthenticationInfo { String ncstring=null; if (nccount != -1) { - ncstring = Integer.toHexString (nccount).toLowerCase(); + ncstring = Integer.toHexString(nccount); int len = ncstring.length(); if (len < 8) ncstring = zeroPad [len] + ncstring; diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java index 02d7e5f030e..cbd24ee2f0b 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java @@ -281,7 +281,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { if (!allowRestrictedHeaders) { restrictedHeaderSet = HashSet.newHashSet(restrictedHeaders.length); for (int i=0; i < restrictedHeaders.length; i++) { - restrictedHeaderSet.add(restrictedHeaders[i].toLowerCase()); + restrictedHeaderSet.add(restrictedHeaders[i].toLowerCase(Locale.ROOT)); } } else { restrictedHeaderSet = null; @@ -485,7 +485,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { return false; } - key = key.toLowerCase(); + key = key.toLowerCase(Locale.ROOT); if (restrictedHeaderSet.contains(key)) { /* * Exceptions to restricted headers: diff --git a/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java b/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java index 676020a11ba..1021503318e 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java +++ b/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.net.Authenticator.RequestorType; import java.util.Base64; import java.util.HashMap; +import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; import sun.net.www.HeaderParser; @@ -110,7 +111,7 @@ class NegotiateAuthentication extends AuthenticationInfo { supported = new HashMap<>(); } String hostname = hci.host; - hostname = hostname.toLowerCase(); + hostname = hostname.toLowerCase(Locale.ROOT); if (supported.containsKey(hostname)) { return supported.get(hostname); } diff --git a/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java b/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java index 744ee6c1e89..a890dadb293 100644 --- a/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java +++ b/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package sun.net.www.protocol.http.spnego; import java.io.IOException; +import java.util.Locale; import org.ietf.jgss.GSSContext; import org.ietf.jgss.GSSException; @@ -90,7 +91,7 @@ public class NegotiatorImpl extends Negotiator { // RFC 4559 4.1 uses uppercase service name "HTTP". // RFC 4120 6.2.1 demands the host be lowercase - String peerName = "HTTP@" + hci.host.toLowerCase(); + String peerName = "HTTP@" + hci.host.toLowerCase(Locale.ROOT); GSSName serverName = manager.createName(peerName, GSSName.NT_HOSTBASED_SERVICE); diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/ContextList.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/ContextList.java index 3be18e9744f..cbedb6ca860 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/ContextList.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/ContextList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ class ContextList { } synchronized HttpContextImpl findContext (String protocol, String path, boolean exact) { - protocol = protocol.toLowerCase(); + protocol = protocol.toLowerCase(Locale.ROOT); String longest = ""; HttpContextImpl lc = null; for (HttpContextImpl ctx: list) { diff --git a/src/jdk.httpserver/share/classes/sun/net/httpserver/HttpContextImpl.java b/src/jdk.httpserver/share/classes/sun/net/httpserver/HttpContextImpl.java index 244422317ca..f1583954115 100644 --- a/src/jdk.httpserver/share/classes/sun/net/httpserver/HttpContextImpl.java +++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/HttpContextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,7 +59,7 @@ class HttpContextImpl extends HttpContext { if (path == null || protocol == null || path.length() < 1 || path.charAt(0) != '/') { throw new IllegalArgumentException ("Illegal value for path or protocol"); } - this.protocol = protocol.toLowerCase(); + this.protocol = protocol.toLowerCase(Locale.ROOT); this.path = path; if (!this.protocol.equals ("http") && !this.protocol.equals ("https")) { throw new IllegalArgumentException ("Illegal value for protocol");