Browse Source

Fixed bug with single char field and bracket notation.

pull/7/head
Kalle Stenflo 13 years ago
parent
commit
824a59d057
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java
  2. 10
      json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java
  3. 2
      json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java

2
json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java

@ -149,7 +149,7 @@ public class PathTokenizer implements Iterable<PathToken> {
src = trimLeft(src, "?"); src = trimLeft(src, "?");
src = trimLeft(src, "@"); src = trimLeft(src, "@");
if (src.length() > 5 && src.subSequence(0, 2).equals("['")) { if (src.length() >= 5 && src.subSequence(0, 2).equals("['")) {
src = src.substring(2); src = src.substring(2);
src = src.substring(0, src.length() - 2); src = src.substring(0, src.length() - 2);
} }

10
json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java

@ -1,5 +1,7 @@
package com.jayway.jsonpath; package com.jayway.jsonpath;
import com.jayway.jsonpath.reader.PathToken;
import com.jayway.jsonpath.reader.PathTokenizer;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
@ -15,8 +17,6 @@ import static org.junit.Assert.assertThat;
*/ */
public class ComplianceTests { public class ComplianceTests {
@Test @Test
public void test_one() throws Exception { public void test_one() throws Exception {
@ -24,12 +24,12 @@ public class ComplianceTests {
" b: \"b\",\n" + " b: \"b\",\n" +
" \"c d\": \"e\" \n" + " \"c d\": \"e\" \n" +
" }"; " }";
assertThat(JsonPath.<String>read(json, "$.a"), is(equalTo("a"))); assertThat(JsonPath.<String>read(json, "$.a"), equalTo("a"));
assertThat(JsonPath.<List<String>>read(json, "$.*"), hasItems("a", "b", "e")); assertThat(JsonPath.<List<String>>read(json, "$.*"), hasItems("a", "b", "e"));
assertThat(JsonPath.<List<String>>read(json, "$['*']"), hasItems("a", "b", "e")); assertThat(JsonPath.<List<String>>read(json, "$['*']"), hasItems("a", "b", "e"));
assertThat(JsonPath.<String>read(json, "$['a']"), equalTo("a"));
//assertThat(JsonPath.<String>read(json, "$['a']"), is(equalTo("a"))); //high
//assertThat(JsonPath.<String>read(json, "$.'c d'"), is(equalTo("e"))); //low //assertThat(JsonPath.<String>read(json, "$.'c d'"), is(equalTo("e"))); //low
//assertThat(JsonPath.<List<String>>read(json, "$[*]"), hasItems("a", "b", "e")); //low //assertThat(JsonPath.<List<String>>read(json, "$[*]"), hasItems("a", "b", "e")); //low

2
json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java

@ -20,6 +20,8 @@ public class SplitPathFragmentsTest {
private JsonProvider jsonProvider = JsonProvider.getInstance(); private JsonProvider jsonProvider = JsonProvider.getInstance();
@Test @Test
public void array_filter_bracket_test() throws Exception { public void array_filter_bracket_test() throws Exception {

Loading…
Cancel
Save