Browse Source

support double quotes as string delimiters in bracket property token

pull/157/head
Jochen Berger 9 years ago
parent
commit
f42517e8aa
  1. 9
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  2. 1
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java

9
json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java

@ -29,6 +29,7 @@ public class PathCompiler {
private static final char SPLIT = ':';
private static final char MINUS = '-';
private static final char TICK = '\'';
private static final char DOUBLE_QUOTE = '"';
private final LinkedList<Predicate> filterStack;
private final CharacterIndex path;
@ -345,7 +346,11 @@ public class PathCompiler {
// ['foo']
//
private boolean readBracketPropertyToken(PathTokenAppender appender) {
if (!path.currentCharIs(OPEN_SQUARE_BRACKET) || !path.nextSignificantCharIs(TICK)) {
if (!path.currentCharIs(OPEN_SQUARE_BRACKET)) {
return false;
}
char potentialStringDelimiter = path.nextSignificantChar();
if (potentialStringDelimiter != TICK && potentialStringDelimiter != DOUBLE_QUOTE) {
return false;
}
@ -361,7 +366,7 @@ public class PathCompiler {
if (c == CLOSE_SQUARE_BRACKET && !inProperty) {
break;
} else if (c == TICK) {
} else if (c == potentialStringDelimiter) {
if (inProperty) {
endPosition = readPosition;
properties.add(path.subSequence(startPosition, endPosition).toString());

1
json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java

@ -59,6 +59,7 @@ public class PathCompilerTest {
assertThat(compile("$['1prop']").toString()).isEqualTo("$['1prop']");
assertThat(compile("$['@prop']").toString()).isEqualTo("$['@prop']");
assertThat(compile("$[ '@prop' ]").toString()).isEqualTo("$['@prop']");
assertThat(compile("$[\"prop\"]").toString()).isEqualTo("$['prop']");
}
@Test

Loading…
Cancel
Save