diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2023-09-19 14:35:38 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-09-25 16:15:33 +0200 |
commit | e53c1864e6cd483c20f761b62e739b3071636767 (patch) | |
tree | b8331a6e33258e6ce00358c8782ed90b44d94639 /org.eclipse.jgit.test | |
parent | a94e54ce872de56d775f213dc4c2e7116a68c4e3 (diff) | |
download | jgit-e53c1864e6cd483c20f761b62e739b3071636767.tar.gz jgit-e53c1864e6cd483c20f761b62e739b3071636767.zip |
[errorprone] FS#searchPath: handle surprising behavior of String#split
See https://errorprone.info/bugpattern/StringSplitter
Change-Id: Ic80f6c53ea96537ed4d046621e774288fced7ce1
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java index 171d80c3da..51236e1cc0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java @@ -13,6 +13,7 @@ package org.eclipse.jgit.util; import static java.time.Instant.EPOCH; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeNoException; import static org.junit.Assume.assumeTrue; @@ -233,4 +234,26 @@ public class FSTest { assertFalse(RepositoryCache.FileKey .isGitRepository(new File("repo.git"), FS.DETECTED)); } + + @Test + public void testSearchPath() throws IOException { + File f1 = new File(trash, "file1"); + FileUtils.createNewFile(f1); + f1.setExecutable(true); + File f2 = new File(trash, "file2"); + FileUtils.createNewFile(f2); + assertEquals(f1, FS.searchPath(trash.getAbsolutePath(), "file1")); + assertNull(FS.searchPath(trash.getAbsolutePath(), "file2")); + } + + @Test + public void testSearchPathEmptyPath() { + assertNull(FS.searchPath("", "file1")); + assertNull(FS.searchPath(File.pathSeparator, "file1")); + assertNull(FS.searchPath(File.pathSeparator + File.pathSeparator, + "file1")); + assertNull(FS.searchPath( + " " + File.pathSeparator + " " + File.pathSeparator + " \t", + "file1")); + } } |