aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-05-15 18:25:52 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2021-05-17 08:31:41 +0200
commitc718e6059c0371dcde83d51f83f3031f934c34b7 (patch)
tree048d2644fd0c88c0ed50bbec9a73c6a6d057430a
parent87704b773654470508de1dc9570914cad168ccf9 (diff)
downloadjgit-c718e6059c0371dcde83d51f83f3031f934c34b7.tar.gz
jgit-c718e6059c0371dcde83d51f83f3031f934c34b7.zip
SSH config: fix whitespace handling
Use Character.isWhitespace() instead of Character.isSpaceChar() to treat TABs as whitespace, too. Change-Id: Iffc59c13357d981ede6a1e0feb6ea6ff03fb3064 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFile.java13
2 files changed, 25 insertions, 5 deletions
diff --git a/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
index 82109582f5..93d85e2e90 100644
--- a/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
+++ b/org.eclipse.jgit.ssh.jsch.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
@@ -572,4 +572,21 @@ public class OpenSshConfigTest extends RepositoryTestCase {
assertArrayEquals(new Object[] { "/foo", "/bar", "/baz" },
h.getConfig().getValues("IdentityFile"));
}
+
+ @Test
+ public void testWhitespace() throws Exception {
+ config("Host foo \tbar baz\nPort 29418\n");
+ Host h = osc.lookup("foo");
+ assertNotNull(h);
+ assertEquals(29418, h.getPort());
+ h = osc.lookup("bar");
+ assertNotNull(h);
+ assertEquals(29418, h.getPort());
+ h = osc.lookup("baz");
+ assertNotNull(h);
+ assertEquals(29418, h.getPort());
+ h = osc.lookup("\tbar");
+ assertNotNull(h);
+ assertEquals(22, h.getPort());
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFile.java
index e4753df00c..bf93d77f7e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFile.java
@@ -273,7 +273,7 @@ public class OpenSshConfigFile implements SshConfigStore {
int length = argument.length();
while (start < length) {
// Skip whitespace
- if (Character.isSpaceChar(argument.charAt(start))) {
+ if (Character.isWhitespace(argument.charAt(start))) {
start++;
continue;
}
@@ -288,7 +288,7 @@ public class OpenSshConfigFile implements SshConfigStore {
} else {
int stop = start + 1;
while (stop < length
- && !Character.isSpaceChar(argument.charAt(stop))) {
+ && !Character.isWhitespace(argument.charAt(stop))) {
stop++;
}
result.add(argument.substring(start, stop));
@@ -355,9 +355,12 @@ public class OpenSshConfigFile implements SshConfigStore {
private static String stripWhitespace(String value) {
final StringBuilder b = new StringBuilder();
- for (int i = 0; i < value.length(); i++) {
- if (!Character.isSpaceChar(value.charAt(i)))
- b.append(value.charAt(i));
+ int length = value.length();
+ for (int i = 0; i < length; i++) {
+ char ch = value.charAt(i);
+ if (!Character.isWhitespace(ch)) {
+ b.append(ch);
+ }
}
return b.toString();
}