diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-09-25 14:42:12 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-09-26 08:31:13 +0900 |
commit | 2f1350c9ac51f421e5642915716f43e732c4eb14 (patch) | |
tree | 0df09945624b113a36751490072e71815efe7494 /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib | |
parent | a7d3fa3064a9c4a7d380415774b2c31ead5672f2 (diff) | |
download | jgit-2f1350c9ac51f421e5642915716f43e732c4eb14.tar.gz jgit-2f1350c9ac51f421e5642915716f43e732c4eb14.zip |
Explicitly specify charset when calling getBytes
Change-Id: Ie492406005be56ccaf4dfb385ae376636404816d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib')
4 files changed, 29 insertions, 25 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index 6e2cddb4ce..30a07421ad 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -48,6 +48,7 @@ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -812,7 +813,7 @@ public class ConfigTest { public void testIncludeTooManyRecursions() throws IOException { File config = tmp.newFile("config"); String include = "[include]\npath=" + pathToString(config) + "\n"; - Files.write(config.toPath(), include.getBytes()); + Files.write(config.toPath(), include.getBytes(UTF_8)); try { loadConfig(config); fail(); @@ -833,7 +834,7 @@ public class ConfigTest { File config = tmp.newFile("config"); String fooBar = "[foo]\nbar=true\n"; - Files.write(config.toPath(), fooBar.getBytes()); + Files.write(config.toPath(), fooBar.getBytes(UTF_8)); Config parsed = parse("[include]\npath=" + pathToString(config) + "\n"); assertFalse(parsed.getBoolean("foo", "bar", false)); @@ -844,11 +845,11 @@ public class ConfigTest { throws IOException, ConfigInvalidException { File included = tmp.newFile("included"); String content = "[foo]\nbar=true\n"; - Files.write(included.toPath(), content.getBytes()); + Files.write(included.toPath(), content.getBytes(UTF_8)); File config = tmp.newFile("config"); content = "[Include]\npath=" + pathToString(included) + "\n"; - Files.write(config.toPath(), content.getBytes()); + Files.write(config.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(config); assertTrue(fbConfig.getBoolean("foo", "bar", false)); @@ -859,11 +860,11 @@ public class ConfigTest { throws IOException, ConfigInvalidException { File included = tmp.newFile("included"); String content = "[foo]\nbar=true\n"; - Files.write(included.toPath(), content.getBytes()); + Files.write(included.toPath(), content.getBytes(UTF_8)); File config = tmp.newFile("config"); content = "[include]\nPath=" + pathToString(included) + "\n"; - Files.write(config.toPath(), content.getBytes()); + Files.write(config.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(config); assertTrue(fbConfig.getBoolean("foo", "bar", false)); @@ -886,11 +887,11 @@ public class ConfigTest { File included = tmp.newFile("included"); String includedPath = pathToString(included); String content = "[include]\npath=\n"; - Files.write(included.toPath(), content.getBytes()); + Files.write(included.toPath(), content.getBytes(UTF_8)); File config = tmp.newFile("config"); String include = "[include]\npath=" + includedPath + "\n"; - Files.write(config.toPath(), include.getBytes()); + Files.write(config.toPath(), include.getBytes(UTF_8)); try { loadConfig(config); fail("Expected ConfigInvalidException"); @@ -917,7 +918,7 @@ public class ConfigTest { 21, 31, CoreConfig.AutoCRLF.FALSE, "+refs/heads/*:refs/remotes/origin/*") + "\n[include]\npath=" + pathToString(includedFile); - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_ORIGIN, REFS_UPSTREAM); @@ -940,7 +941,7 @@ public class ConfigTest { + createAllTypesSampleContent("Alice Parker", false, 11, 21, 31, CoreConfig.AutoCRLF.FALSE, "+refs/heads/*:refs/remotes/origin/*"); - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsConfig(fbConfig, REFS_UPSTREAM, REFS_ORIGIN); @@ -960,7 +961,7 @@ public class ConfigTest { File configFile = tmp.newFile("config"); String content = "[include]\npath=" + pathToString(includedFile); - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_UPSTREAM); @@ -981,7 +982,7 @@ public class ConfigTest { File configFile = tmp.newFile("config"); String content = "[user]\n[include]\npath=" + pathToString(includedFile); - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_UPSTREAM); @@ -1003,7 +1004,7 @@ public class ConfigTest { File configFile = tmp.newFile("config"); String content = "[include]\npath=" + pathToString(includedFile) + "\n[user]"; - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_UPSTREAM); @@ -1024,7 +1025,7 @@ public class ConfigTest { File configFile = tmp.newFile("config"); String content = "[user]\nemail=alice@home\n[include]\npath=" + pathToString(includedFile); - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_UPSTREAM); @@ -1046,7 +1047,7 @@ public class ConfigTest { File configFile = tmp.newFile("config"); String content = "[include]\npath=" + pathToString(includedFile) + "\n[user]\nemail=alice@home\n"; - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); assertValuesAsIncluded(fbConfig, REFS_UPSTREAM); @@ -1066,13 +1067,13 @@ public class ConfigTest { RefSpec includedRefSpec = new RefSpec(REFS_UPSTREAM); String includedContent = "[remote \"origin\"]\n" + "fetch=" + includedRefSpec; - Files.write(includedFile.toPath(), includedContent.getBytes()); + Files.write(includedFile.toPath(), includedContent.getBytes(UTF_8)); File configFile = tmp.newFile("config"); RefSpec refSpec = new RefSpec(REFS_ORIGIN); String content = "[include]\npath=" + pathToString(includedFile) + "\n" + "[remote \"origin\"]\n" + "fetch=" + refSpec; - Files.write(configFile.toPath(), content.getBytes()); + Files.write(configFile.toPath(), content.getBytes(UTF_8)); FileBasedConfig fbConfig = loadConfig(configFile); @@ -1094,7 +1095,7 @@ public class ConfigTest { String includedContent = createAllTypesSampleContent("Alice Muller", true, 10, 20, 30, CoreConfig.AutoCRLF.TRUE, "+refs/heads/*:refs/remotes/upstream/*"); - Files.write(includedFile.toPath(), includedContent.getBytes()); + Files.write(includedFile.toPath(), includedContent.getBytes(UTF_8)); return includedFile; } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java index 32a1ec96a5..057e0c881b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java @@ -37,6 +37,7 @@ */ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -343,7 +344,7 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { ObjectInserter newObjectInserter; newObjectInserter = git.getRepository().newObjectInserter(); ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, - "data".getBytes()); + "data".getBytes(UTF_8)); newObjectInserter = git.getRepository().newObjectInserter(); FileMode mode = FileMode.REGULAR_FILE; ObjectId insertId = blobId; @@ -366,8 +367,8 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { insertId = blobId; for (int i = path.length - 1; i >= 0; --i) { TreeFormatter treeFormatter = new TreeFormatter(); - treeFormatter.append(path[i].getBytes(), 0, - path[i].getBytes().length, + treeFormatter.append(path[i].getBytes(UTF_8), 0, + path[i].getBytes(UTF_8).length, mode, insertId, true); insertId = newObjectInserter.insert(treeFormatter); mode = FileMode.TREE; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index eb87827805..7cb91a2064 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -40,6 +40,7 @@ */ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -310,7 +311,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { assertTrue("unexpected content for path " + path + " in index. Expected: <" + expectedValue + ">", Arrays.equals(db.open(read.getEntry(j).getObjectId()) - .getCachedBytes(), i.get(path).getBytes())); + .getCachedBytes(), i.get(path).getBytes(UTF_8))); } } @@ -405,7 +406,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { ObjectId genSha1(String data) { try (ObjectInserter w = db.newObjectInserter()) { - ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes()); + ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes(UTF_8)); w.flush(); return id; } catch (IOException e) { @@ -2048,7 +2049,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { assertArrayEquals( "unexpected content for path " + path + " in workDir. ", - buffer, i.get(path).getBytes()); + buffer, i.get(path).getBytes(UTF_8)); } nrFiles++; } else if (file.isDirectory()) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java index ac142ed322..7d2c4a2784 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -261,7 +262,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertEquals(Storage.PACKED, ref.getStorage()); try (FileOutputStream os = new FileOutputStream( new File(db.getDirectory(), "refs/heads/master"))) { - os.write(ref.getObjectId().name().getBytes()); + os.write(ref.getObjectId().name().getBytes(UTF_8)); os.write('\n'); } |