parse("[foo \"bar\" ]\nfoo=bar\n");
}
+ @Test
+ public void testCrLf() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("true\r\n"));
+ }
+
+ @Test
+ public void testLfContinuation() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("tr\\\nue"));
+ }
+
+ @Test
+ public void testCrCharContinuation() throws ConfigInvalidException {
+ expectedEx.expect(ConfigInvalidException.class);
+ expectedEx.expectMessage("Bad escape: \\u000d");
+ parseEscapedValue("tr\\\rue");
+ }
+
+ @Test
+ public void testCrEOFContinuation() throws ConfigInvalidException {
+ expectedEx.expect(ConfigInvalidException.class);
+ expectedEx.expectMessage("Bad escape: \\u000d");
+ parseEscapedValue("tr\\\r");
+ }
+
+ @Test
+ public void testCrLfContinuation() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("tr\\\r\nue"));
+ }
+
+ @Test
+ public void testWhitespaceContinuation() throws ConfigInvalidException {
+ assertEquals("tr ue", parseEscapedValue("tr \\\n ue"));
+ assertEquals("tr ue", parseEscapedValue("tr \\\r\n ue"));
+ }
+
private static void assertValueRoundTrip(String value)
throws ConfigInvalidException {
assertValueRoundTrip(value, value);
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) {
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>