Skip to content

Commit b5818d1

Browse files
committed
PropertiesParser: warn on odd num backslashes
this also shows a warning in Eclipse when single backslash is detected and testcase Signed-off-by: Christoph Rueger <[email protected]>
1 parent 246dbe2 commit b5818d1

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

aQute.libg/src/aQute/lib/utf8properties/PropertiesParser.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,6 @@ private char backslash() {
371371
return (char) Integer.parseInt(unicode, 16);
372372
}
373373

374-
case ':' :
375-
case '=' :
376-
return c;
377374
case 't' :
378375
return '\t';
379376
case 'f' :
@@ -384,15 +381,29 @@ private char backslash() {
384381
return '\n';
385382
case '\\' :
386383
return '\\';
384+
case ':' :
385+
case '=' :
386+
case '#' :
387+
case '!' :
388+
return c;
387389

388-
case '\f' :
389-
case '\t' :
390390
case ' ' :
391+
case '\t' :
392+
// whitespace immediately after backslash
391393
warning(
392394
"Found \\<whitespace>. This is allowed in a properties file but not in bnd to prevent mistakes");
393395
return c;
394396

395397
default :
398+
// any other character after backslash not forming a valid
399+
// escape -> warning
400+
if ("tnrf\\'\":=#!".indexOf(c) >= 0 || c == 'u') {
401+
// valid escape -> no warning
402+
return c;
403+
}
404+
warning(
405+
"Found odd number of backslashes before '%s'. These are silently dropped by Java properties parsing and lead to confusing behavior",
406+
c);
396407
return c;
397408
}
398409
}

aQute.libg/test/aQute/lib/utf8properties/UTF8PropertiesTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ public void testErrorsInParsing() throws IOException {
296296
+ "a;b=9", "a;b", 7, "Invalid property key: `a;b`:");
297297
assertError("\n" //
298298
+ "a=\\ \n a;v=4", "a", 1, "Found \\\\<whitespace>", "Invalid property key: `a;v`");
299+
assertError("\n" //
300+
+ "a=\\abc\n", "a", 1, "Found odd number of backslashes before");
301+
assertError("\n" //
302+
+ "a=\\u12G4", "a", 1, "Invalid unicode string");
303+
299304
assertError("\n\n\n\n\n\n\n" //
300305
+ "a", "a", 7, "No value specified for key");
301306
assertError("\npropertyName=property\0Value\n", "propertyName", 1,

0 commit comments

Comments
 (0)