Browse Source

Using square bracket literal in path.

pull/100/merge
Kalle Stenflo 9 years ago
parent
commit
2b66f23dd0
  1. 5
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  2. 13
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

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

@ -368,10 +368,7 @@ public class PathCompiler {
while (path.inBounds(readPosition)) { while (path.inBounds(readPosition)) {
char c = path.charAt(readPosition); char c = path.charAt(readPosition);
if (c == CLOSE_SQUARE_BRACKET) { if (c == CLOSE_SQUARE_BRACKET && !inProperty) {
if (inProperty) {
throw new InvalidPathException("Expected property to be closed at position " + readPosition);
}
break; break;
} else if (c == TICK) { } else if (c == TICK) {
if (inProperty) { if (inProperty) {

13
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -17,6 +17,7 @@ import com.jayway.jsonpath.spi.mapper.GsonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingException; import com.jayway.jsonpath.spi.mapper.MappingException;
import net.minidev.json.JSONAware; import net.minidev.json.JSONAware;
import net.minidev.json.parser.JSONParser; import net.minidev.json.parser.JSONParser;
import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
@ -831,4 +832,16 @@ public class IssuesTest extends BaseTest {
assertThat(result).containsExactly(1234); assertThat(result).containsExactly(1234);
} }
//https://groups.google.com/forum/#!topic/jsonpath/Ojv8XF6LgqM
@Test
public void using_square_bracket_literal_path() {
String json = "{ \"valid key[@num = 2]\" : \"value\" }";
String result = JsonPath.read(json, "$['valid key[@num = 2]']");
Assertions.assertThat(result).isEqualTo("value");
}
} }

Loading…
Cancel
Save