* Specify locale in all toLowerCase() and toUpperCase() calls to

avoid "Turkish four i problem"
This commit is contained in:
zzz
2011-11-28 20:32:23 +00:00
parent bf461ee77e
commit d9dcb1e583
50 changed files with 157 additions and 109 deletions

View File

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.util.FileUtil;
@ -51,12 +52,12 @@ public class CPUID {
System.getProperty("os.arch").equals("amd64");
private static final String libPrefix = (System.getProperty("os.name").startsWith("Win") ? "" : "lib");
private static final String libSuffix = (System.getProperty("os.name").startsWith("Win") ? ".dll" : ".so");
private static final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
private static final boolean isLinux = System.getProperty("os.name").toLowerCase().contains("linux");
private static final boolean isFreebsd = System.getProperty("os.name").toLowerCase().contains("freebsd");
private static final boolean isNetbsd = System.getProperty("os.name").toLowerCase().contains("netbsd");
private static final boolean isOpenbsd = System.getProperty("os.name").toLowerCase().contains("openbsd");
private static final boolean isSunos = System.getProperty("os.name").toLowerCase().contains("sunos");
private static final boolean isWindows = System.getProperty("os.name").toLowerCase(Locale.US).contains("windows");
private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
private static final boolean isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
private static final boolean isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
private static final boolean isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
private static final boolean isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
private static final boolean isMac = System.getProperty("os.name").startsWith("Mac");

View File

@ -13,6 +13,7 @@ import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Locale;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
@ -129,7 +130,7 @@ class I2CPSSLSocketFactory {
if (!f.isFile())
continue;
// use file name as alias
String alias = f.getName().toLowerCase();
String alias = f.getName().toLowerCase(Locale.US);
boolean success = addCert(f, alias, ks);
if (success)
added++;

View File

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
@ -229,7 +230,7 @@ public class BlockfileNamingService extends DummyNamingService {
int split = line.indexOf('=');
if (split <= 0)
continue;
String key = line.substring(0, split).toLowerCase();
String key = line.substring(0, split).toLowerCase(Locale.US);
if (line.indexOf('#') > 0) { // trim off any end of line comment
line = line.substring(0, line.indexOf('#')).trim();
if (line.length() < split + 1)
@ -622,11 +623,11 @@ public class BlockfileNamingService extends DummyNamingService {
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p"))
return null;
}
String key = hostname.toLowerCase();
String key = hostname.toLowerCase(Locale.US);
synchronized(_bf) {
if (_isClosed)
return null;
@ -681,7 +682,7 @@ public class BlockfileNamingService extends DummyNamingService {
_log.error("Add entry failed, read-only hosts database");
return false;
}
String key = hostname.toLowerCase();
String key = hostname.toLowerCase(Locale.US);
String listname = FALLBACK_LIST;
Properties props = new Properties();
props.setProperty(PROP_ADDED, Long.toString(_context.clock().now()));
@ -735,7 +736,7 @@ public class BlockfileNamingService extends DummyNamingService {
_log.error("Remove entry failed, read-only hosts database");
return false;
}
String key = hostname.toLowerCase();
String key = hostname.toLowerCase(Locale.US);
String listname = FALLBACK_LIST;
if (options != null) {
String list = options.getProperty("list");

View File

@ -8,6 +8,7 @@
package net.i2p.client.naming;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
@ -64,7 +65,7 @@ class DummyNamingService extends NamingService {
}
// Try Base32 decoding
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p") &&
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p") &&
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
if (d != null) {

View File

@ -7,6 +7,7 @@ package net.i2p.client.naming;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.data.Destination;
@ -46,7 +47,7 @@ public class EepGetAndAddNamingService extends EepGetNamingService {
public Destination lookup(String hostname) {
Destination rv = super.lookup(hostname);
if (rv != null) {
hostname = hostname.toLowerCase();
hostname = hostname.toLowerCase(Locale.US);
// If it's long, assume it's a key.
if (hostname.length() < 516 && hostname.endsWith(".i2p") && ! hostname.endsWith(".b32.i2p")) {
File f = new File(_context.getRouterDir(), DEFAULT_HOSTS_FILE);

View File

@ -7,6 +7,7 @@ package net.i2p.client.naming;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.StringTokenizer;
@ -65,7 +66,7 @@ public class EepGetNamingService extends DummyNamingService {
if (d != null)
return d;
hostname = hostname.toLowerCase();
hostname = hostname.toLowerCase(Locale.US);
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.endsWith(".b32.i2p"))
return null;

View File

@ -5,6 +5,7 @@
package net.i2p.client.naming;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import net.i2p.I2PAppContext;
@ -65,10 +66,10 @@ public class ExecNamingService extends DummyNamingService {
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p"))
return null;
hostname = hostname.toLowerCase();
hostname = hostname.toLowerCase(Locale.US);
// lookup
String key = fetchAddr(hostname);

View File

@ -10,6 +10,7 @@ package net.i2p.client.naming;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
@ -62,22 +63,22 @@ public class HostsTxtNamingService extends MetaNamingService {
// If it's long, assume it's a key.
if (hostname.length() >= DEST_SIZE)
return lookupBase64(hostname);
return super.lookup(hostname.toLowerCase(), lookupOptions, storedOptions);
return super.lookup(hostname.toLowerCase(Locale.US), lookupOptions, storedOptions);
}
@Override
public boolean put(String hostname, Destination d, Properties options) {
return super.put(hostname.toLowerCase(), d, options);
return super.put(hostname.toLowerCase(Locale.US), d, options);
}
@Override
public boolean putIfAbsent(String hostname, Destination d, Properties options) {
return super.putIfAbsent(hostname.toLowerCase(), d, options);
return super.putIfAbsent(hostname.toLowerCase(Locale.US), d, options);
}
@Override
public boolean remove(String hostname, Properties options) {
return super.remove(hostname.toLowerCase(), options);
return super.remove(hostname.toLowerCase(Locale.US), options);
}
/**

View File

@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -101,7 +102,7 @@ public class MetaNamingService extends DummyNamingService {
if (d != null)
return d;
// Base32 failed?
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase().endsWith(".b32.i2p"))
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p"))
return null;
for (NamingService ns : _services) {

View File

@ -36,6 +36,7 @@ import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
@ -371,7 +372,7 @@ public class DataHelper {
//val = val.replaceAll("\\\\n","\n");
if ( (key.length() > 0) && (val.length() > 0) )
if (forceLowerCase)
props.setProperty(key.toLowerCase(), val);
props.setProperty(key.toLowerCase(Locale.US), val);
else
props.setProperty(key, val);
}

View File

@ -290,7 +290,7 @@ public class Timestamper implements Runnable {
if (country == null) {
country = Locale.getDefault().getCountry();
if (country != null)
country = country.toLowerCase();
country = country.toLowerCase(Locale.US);
}
if (country != null && country.length() > 0) {
_priorityServers = new ArrayList(3);

View File

@ -1,5 +1,7 @@
package net.i2p.util;
import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.data.Base32;
import net.i2p.data.DataFormatException;
@ -29,7 +31,7 @@ public class ConvertToHash {
if (peer == null)
return null;
Hash h = new Hash();
String peerLC = peer.toLowerCase();
String peerLC = peer.toLowerCase(Locale.US);
// b64 hash
if (peer.length() == 44 && !peerLC.endsWith(".i2p")) {
try {

View File

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
@ -949,13 +950,13 @@ public class EepGet {
} else if (key.equalsIgnoreCase("Last-Modified")) {
_lastModified = val;
} else if (key.equalsIgnoreCase("Transfer-encoding")) {
_encodingChunked = val.toLowerCase().contains("chunked");
_encodingChunked = val.toLowerCase(Locale.US).contains("chunked");
} else if (key.equalsIgnoreCase("Content-encoding")) {
// This is kindof a hack, but if we are downloading a gzip file
// we don't want to transparently gunzip it and save it as a .gz file.
// A query string will also mess this up
if ((!_actualURL.endsWith(".gz")) && (!_actualURL.endsWith(".tgz")))
_isGzippedResponse = val.toLowerCase().contains("gzip");
_isGzippedResponse = val.toLowerCase(Locale.US).contains("gzip");
} else if (key.equalsIgnoreCase("Content-Type")) {
_contentType=val;
} else if (key.equalsIgnoreCase("Location")) {

View File

@ -9,6 +9,8 @@ package net.i2p.util;
*
*/
import java.util.Locale;
import net.i2p.I2PAppContext;
/**
@ -44,7 +46,7 @@ public class Log {
public static int getLevel(String level) {
if (level == null) return Log.CRIT;
level = level.toUpperCase();
level = level.toUpperCase(Locale.US);
if (STR_DEBUG.startsWith(level)) return DEBUG;
if (STR_INFO.startsWith(level)) return INFO;
if (STR_WARN.startsWith(level)) return WARN;

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
@ -312,9 +313,9 @@ public class LogManager {
if (disp == null)
_displayOnScreen = DEFAULT_DISPLAYONSCREEN;
else {
if ("TRUE".equals(disp.toUpperCase().trim()))
if ("TRUE".equals(disp.toUpperCase(Locale.US).trim()))
_displayOnScreen = true;
else if ("YES".equals(disp.toUpperCase().trim()))
else if ("YES".equals(disp.toUpperCase(Locale.US).trim()))
_displayOnScreen = true;
else
_displayOnScreen = false;
@ -463,7 +464,7 @@ public class LogManager {
*/
public static int getFileSize(String size) {
try {
String v = size.trim().toUpperCase();
String v = size.trim().toUpperCase(Locale.US);
if (v.length() < 2)
return -1;
if (v.endsWith("B"))

View File

@ -19,6 +19,7 @@ import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import freenet.support.CPUInformation.AMDCPUInfo;
@ -155,11 +156,11 @@ public class NativeBigInteger extends BigInteger {
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
private static final boolean _isOS2 = System.getProperty("os.name").startsWith("OS/2");
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
private static final boolean _isLinux = System.getProperty("os.name").toLowerCase().contains("linux");
private static final boolean _isFreebsd = System.getProperty("os.name").toLowerCase().contains("freebsd");
private static final boolean _isNetbsd = System.getProperty("os.name").toLowerCase().contains("netbsd");
private static final boolean _isOpenbsd = System.getProperty("os.name").toLowerCase().contains("openbsd");
private static final boolean _isSunos = System.getProperty("os.name").toLowerCase().contains("sunos");
private static final boolean _isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
private static final boolean _isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
private static final boolean _isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
private static final boolean _isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
private static final boolean _isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
/*

View File

@ -58,6 +58,7 @@ import java.security.cert.CertificateNotYetValidException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Locale;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocketFactory;
@ -302,7 +303,7 @@ public class SSLEepGet extends EepGet {
// use file name as alias
// https://www.sslshopper.com/ssl-converter.html
// No idea if all these formats can actually be read by CertificateFactory
String alias = f.getName().toLowerCase();
String alias = f.getName().toLowerCase(Locale.US);
if (alias.endsWith(".crt") || alias.endsWith(".pem") || alias.endsWith(".key") ||
alias.endsWith(".der") || alias.endsWith(".key") || alias.endsWith(".p7b") ||
alias.endsWith(".p7c") || alias.endsWith(".pfx") || alias.endsWith(".p12"))