diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonContext.java b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonContext.java index 76985f78..a0cc670e 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonContext.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonContext.java @@ -74,7 +74,7 @@ public String jsonString() { @Override public T read(String path, Predicate... filters) { notEmpty(path, "path can not be null or empty"); - return read(pathFromCache(path, filters)); + return read(pathFromCache(path.trim(), filters)); } @Override diff --git a/json-path/src/test/java/com/jayway/jsonpath/Issue_1001.java b/json-path/src/test/java/com/jayway/jsonpath/Issue_1001.java new file mode 100644 index 00000000..702335b1 --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/Issue_1001.java @@ -0,0 +1,20 @@ +package com.jayway.jsonpath; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class Issue_1001 { + @Test + public void testTrailingNewlineInPath() { + String context = "{\n" + + " \"level_0\": {\n" + + " \"level_1\": {\n" + + " \"level_2\": \"At level 2\"\n" + + " }\n" + + " }\n" + + "}"; + String result = JsonPath.read(context, "$.level_0.level_1.level_2\n"); + assertThat(result).isEqualTo("At level 2"); + } +}