From 9fc98a2d42609e634850a96ecc3a836a80ee79e9 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Tue, 24 Nov 2015 16:41:56 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfbc4c3d..e2661b8c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ The function output is dictated by the function itself. Filter Operators ----------------- -Filters are logical expressions used to filter arrays. A typical filter would be `[?(@.age > 18)]` where `@` represents the current item being processed. More complex filters can be created with logical operators `&&` and `||`. String literals must be enclosed by single quotes `[?(@.color == 'blue')]`. +Filters are logical expressions used to filter arrays. A typical filter would be `[?(@.age > 18)]` where `@` represents the current item being processed. More complex filters can be created with logical operators `&&` and `||`. String literals must be enclosed by single or double quotes (`[?(@.color == 'blue')]` or `[?(@.color == "blue")]`). | Operator | Description | | :----------------------- | :---------------------------------------------------------------- | From f42517e8aa71b784b0ad308e7fa4aeebaee120b4 Mon Sep 17 00:00:00 2001 From: Jochen Berger Date: Wed, 25 Nov 2015 12:14:55 +0100 Subject: [PATCH 2/2] support double quotes as string delimiters in bracket property token --- .../com/jayway/jsonpath/internal/path/PathCompiler.java | 9 +++++++-- .../test/java/com/jayway/jsonpath/PathCompilerTest.java | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java b/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java index e4fcd311..0795ffc0 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java +++ b/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 filterStack; private final CharacterIndex path; @@ -345,9 +346,13 @@ 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; + } List properties = new ArrayList(); @@ -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()); diff --git a/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java b/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java index 2c232cca..a0d477fe 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java +++ b/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