Skip to content

Commit de29f60

Browse files
P4Awdjknack
authored andcommitted
if character at position 0 in a string literal the PathCompiler matches the parent path group instead of the string literal group (#618)
1 parent 80d8457 commit de29f60

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

handlebars/src/main/java/com/github/jknack/handlebars/PathCompiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public final class PathCompiler {
6969

7070
/** Split pattern. */
7171
private static Pattern pattern = Pattern
72-
.compile("((\\[[^\\[\\]]+])|(../)|([^" + Pattern.quote(DOT_PATH) + "]+))");
72+
.compile("((\\[[^\\[\\]]+])|"
73+
+ "(" + Pattern.quote(PARENT_PATH) + ")|([^" + Pattern.quote(DOT_PATH) + "]+))");
7374

7475
/**
7576
* Not allowed.

handlebars/src/test/java/com/github/jknack/handlebars/PropertyPathParserTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public void testSingleLiteral() {
3939
eq(array("foo.bar.baz"), PathCompiler.compile("[foo.bar.baz]"));
4040
eq(array("foo/bar/baz"), PathCompiler.compile("[foo/bar/baz]"));
4141
eq(array("foo/bar.baz"), PathCompiler.compile("[foo/bar.baz]"));
42+
eq(array("/foo/bar.baz"), PathCompiler.compile("[/foo/bar.baz]"));
43+
eq(array("../foo/bar.baz"), PathCompiler.compile("[../foo/bar.baz]"));
44+
eq(array("./foo/bar.baz"), PathCompiler.compile("[./foo/bar.baz]"));
45+
eq(array("../"), PathCompiler.compile("[../]"));
46+
eq(array("./"), PathCompiler.compile("[./]"));
4247
}
4348

4449
@Test

0 commit comments

Comments
 (0)