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