7065228: To interpret case-insensitive string locale independently

Reviewed-by: dfuchs, naoto, djelinski, jpai, michaelm
This commit is contained in:
Darragh Clarke 2023-05-22 10:53:59 +00:00 committed by Jaikiran Pai
parent a9705196ce
commit 05e99db466
20 changed files with 74 additions and 60 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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.

View File

@ -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));
}
/**

View File

@ -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

View File

@ -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:")) {

View File

@ -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;

View File

@ -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() {

View File

@ -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);

View File

@ -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<String,Void> 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));
}
}

View File

@ -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";
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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:

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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");