summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-04-05 21:33:14 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-06-08 01:43:22 +0200
commitf24ad3da66a0ea86f5674fac9442d3b4e4c78aa2 (patch)
treeec130621733d11be3b3e6ce50fe5304a3e951502 /org.eclipse.jgit
parent10ab407fa6414a1c4ae08696c78e078cce078519 (diff)
downloadjgit-f24ad3da66a0ea86f5674fac9442d3b4e4c78aa2.tar.gz
jgit-f24ad3da66a0ea86f5674fac9442d3b4e4c78aa2.zip
Handle escaped CR-LF in git config files
Canonical git treats CR-LF in config files as LF.[1][2] JGit does so, too, except when escaped as a line continuation. Correct this and treat the sequence \-CR-LF as a line continuation. [1] https://github.com/git/git/commit/db2c075d9 [2] https://github.com/git/git/blob/v2.21.0/config.c#L485 Bug: 545850 Change-Id: I51e7378a22c21b3baa3701163c423d04c900af5a Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index 4726975d07..2c01d60381 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -1413,11 +1413,23 @@ public class Config {
case '"':
value.append('"');
continue;
+ case '\r': {
+ int next = in.read();
+ if (next == '\n') {
+ continue; // CR-LF
+ } else if (next >= 0) {
+ in.reset();
+ }
+ break;
+ }
default:
- throw new ConfigInvalidException(MessageFormat.format(
- JGitText.get().badEscape,
- Character.valueOf(((char) c))));
+ break;
}
+ throw new ConfigInvalidException(
+ MessageFormat.format(JGitText.get().badEscape,
+ Character.isAlphabetic(c)
+ ? Character.valueOf(((char) c))
+ : toUnicodeLiteral(c)));
}
if ('"' == c) {
@@ -1430,6 +1442,11 @@ public class Config {
return value.length() > 0 ? value.toString() : null;
}
+ private static String toUnicodeLiteral(int c) {
+ return String.format("\\u%04x", //$NON-NLS-1$
+ Integer.valueOf(c));
+ }
+
/**
* Parses a section of the configuration into an application model object.
* <p>