@ -977,14 +977,25 @@ public class ConfigTest {
}
}
@Test
@Test
public void testEscapeSpecialCharacters ( ) throws ConfigInvalidException {
public void testNoEscapeSpecialCharacters ( ) throws ConfigInvalidException {
assertValueRoundTrip ( "x\\y" , "x\\\\y" ) ;
assertValueRoundTrip ( "x\"y" , "x\\\"y" ) ;
assertValueRoundTrip ( "x\ny" , "x\\ny" ) ;
assertValueRoundTrip ( "x\ty" , "x\\ty" ) ;
assertValueRoundTrip ( "x\by" , "x\\by" ) ;
}
@Test
public void testParseLiteralBackspace ( ) throws ConfigInvalidException {
// This is round-tripped with an escape sequence by JGit, but C git writes
// it out as a literal backslash.
assertEquals ( "x\by" , parseEscapedValue ( "x\by" ) ) ;
}
@Test
public void testEscapeCommentCharacters ( ) throws ConfigInvalidException {
assertValueRoundTrip ( "x#y" , "\"x#y\"" ) ;
assertValueRoundTrip ( "x#y" , "\"x#y\"" ) ;
assertValueRoundTrip ( "x;y" , "\"x;y\"" ) ;
assertValueRoundTrip ( "x;y" , "\"x;y\"" ) ;
assertValueRoundTrip ( "x\\y" , "\"x\\\\y\"" ) ;
assertValueRoundTrip ( "x\"y" , "\"x\\\"y\"" ) ;
assertValueRoundTrip ( "x\ny" , "\"x\\ny\"" ) ;
assertValueRoundTrip ( "x\ty" , "\"x\\ty\"" ) ;
assertValueRoundTrip ( "x\by" , "\"x\\by\"" ) ;
}
}
@Test
@Test
@ -1014,6 +1025,11 @@ public class ConfigTest {
assertEquals ( "baz" , parseEscapedValue ( "baz # comment" ) ) ;
assertEquals ( "baz" , parseEscapedValue ( "baz # comment" ) ) ;
assertEquals ( "baz" , parseEscapedValue ( "baz " + WS + " ; comment" ) ) ;
assertEquals ( "baz" , parseEscapedValue ( "baz " + WS + " ; comment" ) ) ;
assertEquals ( "baz" , parseEscapedValue ( "baz " + WS + " # comment" ) ) ;
assertEquals ( "baz" , parseEscapedValue ( "baz " + WS + " # comment" ) ) ;
assertEquals ( "baz " , parseEscapedValue ( "\"baz \"; comment" ) ) ;
assertEquals ( "baz " , parseEscapedValue ( "\"baz \"# comment" ) ) ;
assertEquals ( "baz " , parseEscapedValue ( "\"baz \" ; comment" ) ) ;
assertEquals ( "baz " , parseEscapedValue ( "\"baz \" # comment" ) ) ;
}
}
@Test
@Test
@ -1045,16 +1061,17 @@ public class ConfigTest {
public void testParseInvalidSubsections ( ) {
public void testParseInvalidSubsections ( ) {
assertInvalidSubsection (
assertInvalidSubsection (
JGitText . get ( ) . newlineInQuotesNotAllowed , "\"x\ny\"" ) ;
JGitText . get ( ) . newlineInQuotesNotAllowed , "\"x\ny\"" ) ;
assertInvalidSubsection (
}
MessageFormat . format ( JGitText . get ( ) . badEscape , 'q' ) , "\"x\\q\"" ) ;
@Test
public void testDropBackslashFromInvalidEscapeSequenceInSubsectionName ( )
throws ConfigInvalidException {
assertEquals ( "x0" , parseEscapedSubsection ( "\"x\\0\"" ) ) ;
assertEquals ( "xq" , parseEscapedSubsection ( "\"x\\q\"" ) ) ;
// Unlike for values, \b, \n, and \t are not valid escape sequences.
// Unlike for values, \b, \n, and \t are not valid escape sequences.
assertInvalidSubsection (
assertEquals ( "xb" , parseEscapedSubsection ( "\"x\\b\"" ) ) ;
MessageFormat . format ( JGitText . get ( ) . badEscape , 'b' ) , "\"x\\b\"" ) ;
assertEquals ( "xn" , parseEscapedSubsection ( "\"x\\n\"" ) ) ;
assertInvalidSubsection (
assertEquals ( "xt" , parseEscapedSubsection ( "\"x\\t\"" ) ) ;
MessageFormat . format ( JGitText . get ( ) . badEscape , 'n' ) , "\"x\\n\"" ) ;
assertInvalidSubsection (
MessageFormat . format ( JGitText . get ( ) . badEscape , 't' ) , "\"x\\t\"" ) ;
}
}
private static void assertValueRoundTrip ( String value )
private static void assertValueRoundTrip ( String value )