diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2017-01-28 15:06:15 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-01-28 15:06:15 +0100 |
commit | a4feeb01945e039b39a246f96a1a91b0e4836f01 (patch) | |
tree | 087e1b48290ed529412e8ad48efa341952ee2f1b /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | 2eb1bebd605852b7ef240e700943dfba7c0a1b3f (diff) | |
download | jgit-a4feeb01945e039b39a246f96a1a91b0e4836f01.tar.gz jgit-a4feeb01945e039b39a246f96a1a91b0e4836f01.zip |
Don't rely on default locale when using toUpperCase() and toLowerCase()
Otherwise these methods may produce unexpected results if used for
strings that are intended to be interpreted locale independently.
Examples are programming language identifiers, protocol keys, and HTML
tags. For instance, "TITLE".toLowerCase() in a Turkish locale returns
"t\u0131tle", where '\u0131' is the LATIN SMALL LETTER DOTLESS I
character.
See
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toLowerCase--
http://blog.thetaphi.de/2012/07/default-locales-default-charsets-and.html
Bug: 511238
Change-Id: Id8d8f37d84d62239c918b81f8d883ed798d87656
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java | 4 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java index 80ece1c26a..0adea0baa7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectIdTest.java @@ -49,6 +49,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Locale; + import org.eclipse.jgit.errors.InvalidObjectIdException; import org.junit.Test; @@ -122,7 +124,7 @@ public class ObjectIdTest { public void test011_toString() { final String x = "0123456789ABCDEFabcdef1234567890abcdefAB"; final ObjectId oid = ObjectId.fromString(x); - assertEquals(x.toLowerCase(), oid.name()); + assertEquals(x.toLowerCase(Locale.ROOT), oid.name()); } @Test(expected = InvalidObjectIdException.class) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java index cc5870ebfe..a60bb39cea 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java @@ -85,6 +85,7 @@ import java.security.Security; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.Set; import java.util.TreeSet; @@ -461,7 +462,7 @@ public class WalkEncryptionTest { Set<String> source = Security.getAlgorithms("Cipher"); Set<String> target = new TreeSet<String>(); for (String algo : source) { - algo = algo.toUpperCase(); + algo = algo.toUpperCase(Locale.ROOT); if (algo.matches(regex)) { target.add(algo); } @@ -759,7 +760,7 @@ public class WalkEncryptionTest { for (String source : cipherSet) { // Standard names are not case-sensitive. // http://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html - String target = algorithm.toUpperCase(); + String target = algorithm.toUpperCase(Locale.ROOT); if (source.equalsIgnoreCase(target)) { return true; } |