HTTPCLIENT-765 - String.toLowerCase() / toUpperCase() should specify Locale.ENGLISH
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@652950 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f761a17460
commit
17bacf5e7f
|
@ -33,6 +33,7 @@ package org.apache.http.auth;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -80,7 +81,7 @@ public final class AuthSchemeRegistry {
|
|||
if (factory == null) {
|
||||
throw new IllegalArgumentException("Authentication scheme factory may not be null");
|
||||
}
|
||||
registeredSchemes.put(name.toLowerCase(), factory);
|
||||
registeredSchemes.put(name.toLowerCase(Locale.ENGLISH), factory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +94,7 @@ public final class AuthSchemeRegistry {
|
|||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name may not be null");
|
||||
}
|
||||
registeredSchemes.remove(name.toLowerCase());
|
||||
registeredSchemes.remove(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +114,7 @@ public final class AuthSchemeRegistry {
|
|||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name may not be null");
|
||||
}
|
||||
AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase());
|
||||
AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (factory != null) {
|
||||
return factory.newInstance(params);
|
||||
} else {
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
package org.apache.http.auth;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.util.LangUtils;
|
||||
|
||||
/**
|
||||
|
@ -104,10 +106,10 @@ public class AuthScope {
|
|||
public AuthScope(final String host, int port,
|
||||
final String realm, final String scheme)
|
||||
{
|
||||
this.host = (host == null) ? ANY_HOST: host.toLowerCase();
|
||||
this.host = (host == null) ? ANY_HOST: host.toLowerCase(Locale.ENGLISH);
|
||||
this.port = (port < 0) ? ANY_PORT: port;
|
||||
this.realm = (realm == null) ? ANY_REALM: realm;
|
||||
this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase();
|
||||
this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/** Creates a new credentials scope for the given
|
||||
|
@ -254,7 +256,7 @@ public class AuthScope {
|
|||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (this.scheme != null) {
|
||||
buffer.append(this.scheme.toUpperCase());
|
||||
buffer.append(this.scheme.toUpperCase(Locale.ENGLISH));
|
||||
buffer.append(' ');
|
||||
}
|
||||
if (this.realm != null) {
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
*/
|
||||
package org.apache.http.conn.scheme;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.util.LangUtils;
|
||||
|
||||
/**
|
||||
|
@ -99,7 +101,7 @@ public final class Scheme {
|
|||
("Port is invalid: " + port);
|
||||
}
|
||||
|
||||
this.name = name.toLowerCase();
|
||||
this.name = name.toLowerCase(Locale.ENGLISH);
|
||||
this.socketFactory = factory;
|
||||
this.defaultPort = port;
|
||||
this.layered = (factory instanceof LayeredSocketFactory);
|
||||
|
|
|
@ -43,6 +43,7 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
|
@ -178,12 +179,12 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
|
|||
|
||||
// We're can be case-insensitive when comparing the host we used to
|
||||
// establish the socket to the hostname in the certificate.
|
||||
String hostName = host.trim().toLowerCase();
|
||||
String hostName = host.trim().toLowerCase(Locale.ENGLISH);
|
||||
boolean match = false;
|
||||
for(Iterator<String> it = names.iterator(); it.hasNext();) {
|
||||
// Don't trim the CN, though!
|
||||
String cn = it.next();
|
||||
cn = cn.toLowerCase();
|
||||
cn = cn.toLowerCase(Locale.ENGLISH);
|
||||
// Store CN in StringBuffer in case we need to report an error.
|
||||
buf.append(" <");
|
||||
buf.append(cn);
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
*/
|
||||
package org.apache.http.cookie;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* CookieOrigin class incapsulates details of an origin server that
|
||||
* are relevant when parsing, validating or matching HTTP cookies.
|
||||
|
@ -62,7 +64,7 @@ public final class CookieOrigin {
|
|||
throw new IllegalArgumentException(
|
||||
"Path of origin may not be null.");
|
||||
}
|
||||
this.host = host.toLowerCase();
|
||||
this.host = host.toLowerCase(Locale.ENGLISH);
|
||||
this.port = port;
|
||||
if (!path.trim().equals("")) {
|
||||
this.path = path;
|
||||
|
|
|
@ -34,6 +34,7 @@ package org.apache.http.cookie;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -75,7 +76,7 @@ public final class CookieSpecRegistry {
|
|||
if (factory == null) {
|
||||
throw new IllegalArgumentException("Cookie spec factory may not be null");
|
||||
}
|
||||
registeredSpecs.put(name.toLowerCase(), factory);
|
||||
registeredSpecs.put(name.toLowerCase(Locale.ENGLISH), factory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +88,7 @@ public final class CookieSpecRegistry {
|
|||
if (id == null) {
|
||||
throw new IllegalArgumentException("Id may not be null");
|
||||
}
|
||||
registeredSpecs.remove(id.toLowerCase());
|
||||
registeredSpecs.remove(id.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +108,7 @@ public final class CookieSpecRegistry {
|
|||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name may not be null");
|
||||
}
|
||||
CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase());
|
||||
CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (factory != null) {
|
||||
return factory.newInstance(params);
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
package org.apache.http.impl.auth;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
|
@ -159,7 +160,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
|
|||
if (this.params == null) {
|
||||
return null;
|
||||
}
|
||||
return this.params.get(name.toLowerCase());
|
||||
return this.params.get(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -97,7 +98,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
|
|||
}
|
||||
int endIndex = pos;
|
||||
String s = buffer.substring(beginIndex, endIndex);
|
||||
map.put(s.toLowerCase(), header);
|
||||
map.put(s.toLowerCase(Locale.ENGLISH), header);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -126,7 +127,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
|
|||
AuthScheme authScheme = null;
|
||||
for (Iterator<String> it = authPrefs.iterator(); it.hasNext(); ) {
|
||||
String id = it.next();
|
||||
Header challenge = challenges.get(id.toLowerCase());
|
||||
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
|
||||
if (challenge != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(id + " authentication scheme selected");
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.IOException;
|
|||
import java.io.InterruptedIOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -942,7 +943,7 @@ public class DefaultClientRequestDirector
|
|||
}
|
||||
String id = authScheme.getSchemeName();
|
||||
|
||||
Header challenge = challenges.get(id.toLowerCase());
|
||||
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
|
||||
if (challenge == null) {
|
||||
throw new AuthenticationException(id +
|
||||
" authorization challenge expected, but not found");
|
||||
|
|
|
@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.cookie.ClientCookie;
|
||||
|
@ -197,7 +198,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
|
|||
*/
|
||||
public void setDomain(String domain) {
|
||||
if (domain != null) {
|
||||
cookieDomain = domain.toLowerCase();
|
||||
cookieDomain = domain.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
cookieDomain = null;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.FormattedHeader;
|
||||
import org.apache.http.Header;
|
||||
|
@ -109,7 +110,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
|
|||
}
|
||||
String headervalue = header.getValue();
|
||||
boolean isNetscapeCookie = false;
|
||||
int i1 = headervalue.toLowerCase().indexOf("expires=");
|
||||
int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
|
||||
if (i1 != -1) {
|
||||
i1 += "expires=".length();
|
||||
int i2 = headervalue.indexOf(";", i1);
|
||||
|
|
|
@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.NameValuePair;
|
||||
|
@ -87,7 +88,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
|
|||
NameValuePair[] attribs = headerelement.getParameters();
|
||||
for (int j = attribs.length - 1; j >= 0; j--) {
|
||||
NameValuePair attrib = attribs[j];
|
||||
String s = attrib.getName().toLowerCase();
|
||||
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
cookie.setAttribute(s, attrib.getValue());
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
package org.apache.http.impl.cookie;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.http.cookie.Cookie;
|
||||
|
@ -76,7 +77,7 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
|
|||
* @return True if the specified domain is "special"
|
||||
*/
|
||||
private static boolean isSpecialDomain(final String domain) {
|
||||
final String ucDomain = domain.toUpperCase();
|
||||
final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
|
||||
if (ucDomain.endsWith(".COM")
|
||||
|| ucDomain.endsWith(".EDU")
|
||||
|| ucDomain.endsWith(".NET")
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
*/
|
||||
package org.apache.http.impl.cookie;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.cookie.Cookie;
|
||||
import org.apache.http.cookie.CookieAttributeHandler;
|
||||
import org.apache.http.cookie.CookieOrigin;
|
||||
|
@ -90,7 +92,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
|
|||
+ domain
|
||||
+ "\" violates RFC 2109: domain must contain an embedded dot");
|
||||
}
|
||||
host = host.toLowerCase();
|
||||
host = host.toLowerCase(Locale.ENGLISH);
|
||||
if (!host.endsWith(domain)) {
|
||||
throw new MalformedCookieException(
|
||||
"Illegal domain attribute \"" + domain
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
package org.apache.http.impl.cookie;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.cookie.ClientCookie;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
import org.apache.http.cookie.CookieAttributeHandler;
|
||||
|
@ -67,7 +69,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
|
|||
throw new MalformedCookieException(
|
||||
"Blank value for domain attribute");
|
||||
}
|
||||
domain = domain.toLowerCase();
|
||||
domain = domain.toLowerCase(Locale.ENGLISH);
|
||||
if (!domain.startsWith(".")) {
|
||||
// Per RFC 2965 section 3.2.2
|
||||
// "... If an explicitly specified value does not start with
|
||||
|
@ -112,12 +114,12 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
|
|||
if (origin == null) {
|
||||
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||
}
|
||||
String host = origin.getHost().toLowerCase();
|
||||
String host = origin.getHost().toLowerCase(Locale.ENGLISH);
|
||||
if (cookie.getDomain() == null) {
|
||||
throw new MalformedCookieException("Invalid cookie state: " +
|
||||
"domain not specified");
|
||||
}
|
||||
String cookieDomain = cookie.getDomain().toLowerCase();
|
||||
String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (cookie instanceof ClientCookie
|
||||
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
|
||||
|
@ -176,7 +178,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
|
|||
if (origin == null) {
|
||||
throw new IllegalArgumentException("Cookie origin may not be null");
|
||||
}
|
||||
String host = origin.getHost().toLowerCase();
|
||||
String host = origin.getHost().toLowerCase(Locale.ENGLISH);
|
||||
String cookieDomain = cookie.getDomain();
|
||||
|
||||
// The effective host name MUST domain-match the Domain
|
||||
|
|
|
@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
|
@ -132,11 +133,11 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
new HashMap<String, NameValuePair>(attribs.length);
|
||||
for (int j = attribs.length - 1; j >= 0; j--) {
|
||||
NameValuePair param = attribs[j];
|
||||
attribmap.put(param.getName().toLowerCase(), param);
|
||||
attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
|
||||
}
|
||||
for (Map.Entry<String, NameValuePair> entry: attribmap.entrySet()) {
|
||||
NameValuePair attrib = entry.getValue();
|
||||
String s = attrib.getName().toLowerCase();
|
||||
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
cookie.setAttribute(s, attrib.getValue());
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
package org.apache.http.cookie;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
@ -85,9 +86,9 @@ public class TestCookiePolicy extends TestCase {
|
|||
names = registry.getSpecNames();
|
||||
assertNotNull(names);
|
||||
assertEquals(3, names.size());
|
||||
assertEquals(BROWSER_COMPATIBILITY.toLowerCase(), names.get(0));
|
||||
assertEquals(NETSCAPE.toLowerCase(), names.get(1));
|
||||
assertEquals(RFC_2109.toLowerCase(), names.get(2));
|
||||
assertEquals(BROWSER_COMPATIBILITY.toLowerCase(Locale.ENGLISH), names.get(0));
|
||||
assertEquals(NETSCAPE.toLowerCase(Locale.ENGLISH), names.get(1));
|
||||
assertEquals(RFC_2109.toLowerCase(Locale.ENGLISH), names.get(2));
|
||||
|
||||
registry.unregister(NETSCAPE);
|
||||
registry.unregister(NETSCAPE);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
package org.apache.http.localserver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
|
@ -78,7 +79,7 @@ public class EchoHandler
|
|||
final HttpContext context)
|
||||
throws HttpException, IOException {
|
||||
|
||||
String method = request.getRequestLine().getMethod().toUpperCase();
|
||||
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
|
||||
if (!"GET".equals(method) &&
|
||||
!"POST".equals(method) &&
|
||||
!"PUT".equals(method)
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
@ -82,7 +83,7 @@ public class RandomHandler
|
|||
final HttpContext context)
|
||||
throws HttpException, IOException {
|
||||
|
||||
String method = request.getRequestLine().getMethod().toUpperCase();
|
||||
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
|
||||
if (!"GET".equals(method) && !"HEAD".equals(method)) {
|
||||
throw new MethodNotSupportedException
|
||||
(method + " not supported by " + getClass().getName());
|
||||
|
|
Loading…
Reference in New Issue