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:
Sebastian Bazley 2008-05-02 23:49:48 +00:00
parent f761a17460
commit 17bacf5e7f
19 changed files with 57 additions and 33 deletions

View File

@ -33,6 +33,7 @@ package org.apache.http.auth;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
@ -80,7 +81,7 @@ public final class AuthSchemeRegistry {
if (factory == null) { if (factory == null) {
throw new IllegalArgumentException("Authentication scheme factory may not be 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) { if (name == null) {
throw new IllegalArgumentException("Name may not be 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) { if (name == null) {
throw new IllegalArgumentException("Name may not be 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) { if (factory != null) {
return factory.newInstance(params); return factory.newInstance(params);
} else { } else {

View File

@ -30,6 +30,8 @@
package org.apache.http.auth; package org.apache.http.auth;
import java.util.Locale;
import org.apache.http.util.LangUtils; import org.apache.http.util.LangUtils;
/** /**
@ -104,10 +106,10 @@ public class AuthScope {
public AuthScope(final String host, int port, public AuthScope(final String host, int port,
final String realm, final String scheme) 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.port = (port < 0) ? ANY_PORT: port;
this.realm = (realm == null) ? ANY_REALM: realm; 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 /** Creates a new credentials scope for the given
@ -254,7 +256,7 @@ public class AuthScope {
public String toString() { public String toString() {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if (this.scheme != null) { if (this.scheme != null) {
buffer.append(this.scheme.toUpperCase()); buffer.append(this.scheme.toUpperCase(Locale.ENGLISH));
buffer.append(' '); buffer.append(' ');
} }
if (this.realm != null) { if (this.realm != null) {

View File

@ -30,6 +30,8 @@
*/ */
package org.apache.http.conn.scheme; package org.apache.http.conn.scheme;
import java.util.Locale;
import org.apache.http.util.LangUtils; import org.apache.http.util.LangUtils;
/** /**
@ -99,7 +101,7 @@ public final class Scheme {
("Port is invalid: " + port); ("Port is invalid: " + port);
} }
this.name = name.toLowerCase(); this.name = name.toLowerCase(Locale.ENGLISH);
this.socketFactory = factory; this.socketFactory = factory;
this.defaultPort = port; this.defaultPort = port;
this.layered = (factory instanceof LayeredSocketFactory); this.layered = (factory instanceof LayeredSocketFactory);

View File

@ -43,6 +43,7 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import javax.net.ssl.SSLException; 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 // We're can be case-insensitive when comparing the host we used to
// establish the socket to the hostname in the certificate. // establish the socket to the hostname in the certificate.
String hostName = host.trim().toLowerCase(); String hostName = host.trim().toLowerCase(Locale.ENGLISH);
boolean match = false; boolean match = false;
for(Iterator<String> it = names.iterator(); it.hasNext();) { for(Iterator<String> it = names.iterator(); it.hasNext();) {
// Don't trim the CN, though! // Don't trim the CN, though!
String cn = it.next(); String cn = it.next();
cn = cn.toLowerCase(); cn = cn.toLowerCase(Locale.ENGLISH);
// Store CN in StringBuffer in case we need to report an error. // Store CN in StringBuffer in case we need to report an error.
buf.append(" <"); buf.append(" <");
buf.append(cn); buf.append(cn);

View File

@ -30,6 +30,8 @@
*/ */
package org.apache.http.cookie; package org.apache.http.cookie;
import java.util.Locale;
/** /**
* CookieOrigin class incapsulates details of an origin server that * CookieOrigin class incapsulates details of an origin server that
* are relevant when parsing, validating or matching HTTP cookies. * are relevant when parsing, validating or matching HTTP cookies.
@ -62,7 +64,7 @@ public final class CookieOrigin {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Path of origin may not be null."); "Path of origin may not be null.");
} }
this.host = host.toLowerCase(); this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port; this.port = port;
if (!path.trim().equals("")) { if (!path.trim().equals("")) {
this.path = path; this.path = path;

View File

@ -34,6 +34,7 @@ package org.apache.http.cookie;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
@ -75,7 +76,7 @@ public final class CookieSpecRegistry {
if (factory == null) { if (factory == null) {
throw new IllegalArgumentException("Cookie spec factory may not be 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) { if (id == null) {
throw new IllegalArgumentException("Id may not be 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) { if (name == null) {
throw new IllegalArgumentException("Name may not be 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) { if (factory != null) {
return factory.newInstance(params); return factory.newInstance(params);
} else { } else {

View File

@ -31,6 +31,7 @@
package org.apache.http.impl.auth; package org.apache.http.impl.auth;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.http.Header; import org.apache.http.Header;
@ -159,7 +160,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
if (this.params == null) { if (this.params == null) {
return null; return null;
} }
return this.params.get(name.toLowerCase()); return this.params.get(name.toLowerCase(Locale.ENGLISH));
} }
/** /**

View File

@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -97,7 +98,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
} }
int endIndex = pos; int endIndex = pos;
String s = buffer.substring(beginIndex, endIndex); String s = buffer.substring(beginIndex, endIndex);
map.put(s.toLowerCase(), header); map.put(s.toLowerCase(Locale.ENGLISH), header);
} }
return map; return map;
} }
@ -126,7 +127,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
AuthScheme authScheme = null; AuthScheme authScheme = null;
for (Iterator<String> it = authPrefs.iterator(); it.hasNext(); ) { for (Iterator<String> it = authPrefs.iterator(); it.hasNext(); ) {
String id = it.next(); String id = it.next();
Header challenge = challenges.get(id.toLowerCase()); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) { if (challenge != null) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug(id + " authentication scheme selected"); LOG.debug(id + " authentication scheme selected");

View File

@ -35,6 +35,7 @@ import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -942,7 +943,7 @@ public class DefaultClientRequestDirector
} }
String id = authScheme.getSchemeName(); String id = authScheme.getSchemeName();
Header challenge = challenges.get(id.toLowerCase()); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge == null) { if (challenge == null) {
throw new AuthenticationException(id + throw new AuthenticationException(id +
" authorization challenge expected, but not found"); " authorization challenge expected, but not found");

View File

@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.http.cookie.ClientCookie; import org.apache.http.cookie.ClientCookie;
@ -197,7 +198,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
*/ */
public void setDomain(String domain) { public void setDomain(String domain) {
if (domain != null) { if (domain != null) {
cookieDomain = domain.toLowerCase(); cookieDomain = domain.toLowerCase(Locale.ENGLISH);
} else { } else {
cookieDomain = null; cookieDomain = null;
} }

View File

@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.apache.http.FormattedHeader; import org.apache.http.FormattedHeader;
import org.apache.http.Header; import org.apache.http.Header;
@ -109,7 +110,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
} }
String headervalue = header.getValue(); String headervalue = header.getValue();
boolean isNetscapeCookie = false; boolean isNetscapeCookie = false;
int i1 = headervalue.toLowerCase().indexOf("expires="); int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
if (i1 != -1) { if (i1 != -1) {
i1 += "expires=".length(); i1 += "expires=".length();
int i2 = headervalue.indexOf(";", i1); int i2 = headervalue.indexOf(";", i1);

View File

@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
@ -87,7 +88,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
NameValuePair[] attribs = headerelement.getParameters(); NameValuePair[] attribs = headerelement.getParameters();
for (int j = attribs.length - 1; j >= 0; j--) { for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair attrib = attribs[j]; NameValuePair attrib = attribs[j];
String s = attrib.getName().toLowerCase(); String s = attrib.getName().toLowerCase(Locale.ENGLISH);
cookie.setAttribute(s, attrib.getValue()); cookie.setAttribute(s, attrib.getValue());

View File

@ -30,6 +30,7 @@
*/ */
package org.apache.http.impl.cookie; package org.apache.http.impl.cookie;
import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.apache.http.cookie.Cookie; import org.apache.http.cookie.Cookie;
@ -76,7 +77,7 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
* @return True if the specified domain is "special" * @return True if the specified domain is "special"
*/ */
private static boolean isSpecialDomain(final String domain) { private static boolean isSpecialDomain(final String domain) {
final String ucDomain = domain.toUpperCase(); final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
if (ucDomain.endsWith(".COM") if (ucDomain.endsWith(".COM")
|| ucDomain.endsWith(".EDU") || ucDomain.endsWith(".EDU")
|| ucDomain.endsWith(".NET") || ucDomain.endsWith(".NET")

View File

@ -30,6 +30,8 @@
*/ */
package org.apache.http.impl.cookie; package org.apache.http.impl.cookie;
import java.util.Locale;
import org.apache.http.cookie.Cookie; import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler; import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin; import org.apache.http.cookie.CookieOrigin;
@ -90,7 +92,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
+ domain + domain
+ "\" violates RFC 2109: domain must contain an embedded dot"); + "\" violates RFC 2109: domain must contain an embedded dot");
} }
host = host.toLowerCase(); host = host.toLowerCase(Locale.ENGLISH);
if (!host.endsWith(domain)) { if (!host.endsWith(domain)) {
throw new MalformedCookieException( throw new MalformedCookieException(
"Illegal domain attribute \"" + domain "Illegal domain attribute \"" + domain

View File

@ -31,6 +31,8 @@
package org.apache.http.impl.cookie; package org.apache.http.impl.cookie;
import java.util.Locale;
import org.apache.http.cookie.ClientCookie; import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie; import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler; import org.apache.http.cookie.CookieAttributeHandler;
@ -67,7 +69,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
throw new MalformedCookieException( throw new MalformedCookieException(
"Blank value for domain attribute"); "Blank value for domain attribute");
} }
domain = domain.toLowerCase(); domain = domain.toLowerCase(Locale.ENGLISH);
if (!domain.startsWith(".")) { if (!domain.startsWith(".")) {
// Per RFC 2965 section 3.2.2 // Per RFC 2965 section 3.2.2
// "... If an explicitly specified value does not start with // "... If an explicitly specified value does not start with
@ -112,12 +114,12 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
if (origin == null) { if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be 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) { if (cookie.getDomain() == null) {
throw new MalformedCookieException("Invalid cookie state: " + throw new MalformedCookieException("Invalid cookie state: " +
"domain not specified"); "domain not specified");
} }
String cookieDomain = cookie.getDomain().toLowerCase(); String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH);
if (cookie instanceof ClientCookie if (cookie instanceof ClientCookie
&& ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) { && ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) {
@ -176,7 +178,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
if (origin == null) { if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be 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(); String cookieDomain = cookie.getDomain();
// The effective host name MUST domain-match the Domain // The effective host name MUST domain-match the Domain

View File

@ -33,6 +33,7 @@ package org.apache.http.impl.cookie;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.http.Header; import org.apache.http.Header;
@ -132,11 +133,11 @@ public class RFC2965Spec extends RFC2109Spec {
new HashMap<String, NameValuePair>(attribs.length); new HashMap<String, NameValuePair>(attribs.length);
for (int j = attribs.length - 1; j >= 0; j--) { for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair param = attribs[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()) { for (Map.Entry<String, NameValuePair> entry: attribmap.entrySet()) {
NameValuePair attrib = entry.getValue(); NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase(); String s = attrib.getName().toLowerCase(Locale.ENGLISH);
cookie.setAttribute(s, attrib.getValue()); cookie.setAttribute(s, attrib.getValue());

View File

@ -31,6 +31,7 @@
package org.apache.http.cookie; package org.apache.http.cookie;
import java.util.List; import java.util.List;
import java.util.Locale;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -85,9 +86,9 @@ public class TestCookiePolicy extends TestCase {
names = registry.getSpecNames(); names = registry.getSpecNames();
assertNotNull(names); assertNotNull(names);
assertEquals(3, names.size()); assertEquals(3, names.size());
assertEquals(BROWSER_COMPATIBILITY.toLowerCase(), names.get(0)); assertEquals(BROWSER_COMPATIBILITY.toLowerCase(Locale.ENGLISH), names.get(0));
assertEquals(NETSCAPE.toLowerCase(), names.get(1)); assertEquals(NETSCAPE.toLowerCase(Locale.ENGLISH), names.get(1));
assertEquals(RFC_2109.toLowerCase(), names.get(2)); assertEquals(RFC_2109.toLowerCase(Locale.ENGLISH), names.get(2));
registry.unregister(NETSCAPE); registry.unregister(NETSCAPE);
registry.unregister(NETSCAPE); registry.unregister(NETSCAPE);

View File

@ -32,6 +32,7 @@
package org.apache.http.localserver; package org.apache.http.localserver;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpEntityEnclosingRequest;
@ -78,7 +79,7 @@ public class EchoHandler
final HttpContext context) final HttpContext context)
throws HttpException, IOException { throws HttpException, IOException {
String method = request.getRequestLine().getMethod().toUpperCase(); String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!"GET".equals(method) && if (!"GET".equals(method) &&
!"POST".equals(method) && !"POST".equals(method) &&
!"PUT".equals(method) !"PUT".equals(method)

View File

@ -35,6 +35,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Locale;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
@ -82,7 +83,7 @@ public class RandomHandler
final HttpContext context) final HttpContext context)
throws HttpException, IOException { throws HttpException, IOException {
String method = request.getRequestLine().getMethod().toUpperCase(); String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!"GET".equals(method) && !"HEAD".equals(method)) { if (!"GET".equals(method) && !"HEAD".equals(method)) {
throw new MethodNotSupportedException throw new MethodNotSupportedException
(method + " not supported by " + getClass().getName()); (method + " not supported by " + getClass().getName());