Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for trailing newline character in path to evaluate on a json #1002

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String jsonString() {
@Override
public <T> 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
Expand Down
20 changes: 20 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/Issue_1001.java
Original file line number Diff line number Diff line change
@@ -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");
}
}