git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing

From
GGGilion Goudsmit <ggoudsmit@shebang.nl>
Date
Sep 20, 2008, 20:33 UTC
Message-ID
<12219428213749-git-send-email-ggoudsmit@shebang.nl>

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
Next: Jonas Fonseca
Message 1 of 16 in “Fixed a bug that caused tabs in ~/.ssh/config to break parsing”
  1. Fixed a bug that caused tabs in ~/.ssh/config to break parsingGilion Goudsmit, Sep 20, 2008
  2. Add test for OpenSshConfig separator parsingJonas Fonseca, Sep 20, 2008
  3. Add test for OpenSshConfig separator parsingJonas Fonseca, Sep 20, 2008
  4. Robin RosenbergSep 20, 2008
  5. Jonas FonsecaSep 20, 2008
  6. Test and fix handling of quotes in ~/.ssh/configJonas Fonseca, Sep 21, 2008
  7. Robin RosenbergSep 22, 2008
  8. Shawn O. PearceSep 22, 2008
  9. Jonas FonsecaSep 24, 2008
  10. Shawn O. PearceSep 24, 2008
  11. Add tests for handling of parsing errors in OpenSshConfigJonas Fonseca, Sep 25, 2008
  12. Robin RosenbergSep 25, 2008
  13. Improve handling of parsing errors in OpenSshConfigJonas Fonseca, Sep 25, 2008
  14. Jonas FonsecaSep 25, 2008
  15. Shawn O. PearceSep 25, 2008
  16. Robin RosenbergSep 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.