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>
This commit is contained in:
parent
87704b7736
commit
c718e6059c
|
@ -572,4 +572,21 @@ public void testMultipleMatch() throws Exception {
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ private List<String> parseList(String argument) {
|
|||
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 @@ private List<String> parseList(String argument) {
|
|||
} 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 @@ private static String dequote(String value) {
|
|||
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue