git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing
@ 2008-09-20 20:33 Gilion Goudsmit
  2008-09-20 21:48 ` [JGIT PATCH] Add test for OpenSshConfig separator parsing Jonas Fonseca
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Gilion Goudsmit @ 2008-09-20 20:33 UTC (permalink / raw)
  To: git; +Cc: spearce, Gilion Goudsmit

Having only tab-characters separating a key and value in the
users ~/.ssh/config would cause the config-parser to fail with
a "String index out of range: -1" exception. Also simplified
the line parsing code my using a two argument split.

Signed-off-by: Gilion Goudsmit <ggoudsmit@shebang.nl>
---
 .../org/spearce/jgit/transport/OpenSshConfig.java  |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
index df38e18..5bfcf5f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
@@ -167,17 +167,9 @@ while ((line = br.readLine()) != null) {
 			if (line.length() == 0 || line.startsWith("#"))
 				continue;
 
-			final int sp = line.indexOf(' ');
-			final int eq = line.indexOf('=');
-			final int splitAt;
-			if (sp >= 0 && eq >= 0)
-				splitAt = Math.min(sp, eq);
-			else if (sp < 0)
-				splitAt = eq;
-			else
-				splitAt = sp;
-			final String keyword = line.substring(0, splitAt).trim();
-			final String argValue = line.substring(splitAt + 1).trim();
+			final String[] parts = line.split("[ \t=]", 2);
+			final String keyword = parts[0].trim();
+			final String argValue = parts[1].trim();
 
 			if ("Host".equalsIgnoreCase(keyword)) {
 				current.clear();
-- 
1.5.3.8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-09-25 15:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-20 20:33 [JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing Gilion Goudsmit
2008-09-20 21:48 ` [JGIT PATCH] Add test for OpenSshConfig separator parsing Jonas Fonseca
2008-09-20 22:33   ` Jonas Fonseca
2008-09-20 22:18 ` [JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing Robin Rosenberg
2008-09-20 22:29 ` Jonas Fonseca
     [not found]   ` <bd6139dc0809201819o5d6eb5b1r7bf0e46702c711d7@mail.gmail.com>
2008-09-21 11:25     ` [JGIT PATCH] Test and fix handling of quotes in ~/.ssh/config Jonas Fonseca
2008-09-22 20:42       ` Robin Rosenberg
2008-09-22 21:07         ` Shawn O. Pearce
2008-09-24 23:25           ` Jonas Fonseca
2008-09-24 23:31             ` Shawn O. Pearce
2008-09-25  8:39               ` [JGIT PATCH] Add tests for handling of parsing errors in OpenSshConfig Jonas Fonseca
2008-09-25 11:33                 ` Robin Rosenberg
2008-09-25 13:29                   ` [JGIT RFC PATCH] Improve " Jonas Fonseca
2008-09-25 14:30                     ` Jonas Fonseca
2008-09-25 15:16                     ` Shawn O. Pearce
2008-09-25  6:26             ` [JGIT PATCH] Test and fix handling of quotes in ~/.ssh/config Robin Rosenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).