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

fix 620 #693

Merged
merged 1 commit into from Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -333,7 +333,8 @@ else if (isPathContext(c)) {
// we've encountered a COMMA do the same
case CLOSE_PARENTHESIS:
groupParen--;
if (0 != groupParen) {
//CS304 Issue link: https://github.com/json-path/JsonPath/issues/620
if (0 > groupParen ) {
parameter.append(c);
}
case COMMA:
Expand Down
73 changes: 71 additions & 2 deletions json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java
Expand Up @@ -1021,7 +1021,7 @@ public void issue_309(){
assertThat((String)doc.read("$.jsonArr[0].name")).isEqualTo("nOne");
assertThat((String)doc.read("$.jsonArr[1].name")).isEqualTo("Jayway");
}

@Test
public void issue_378(){

Expand All @@ -1039,12 +1039,81 @@ public void issue_378(){
.jsonProvider(new JacksonJsonNodeJsonProvider())
.mappingProvider(new JacksonMappingProvider())
.build();

DocumentContext ctx = JsonPath.using(configuration).parse(json);

String path = "$.nodes[*][?(!([\"1.2.3.4\"] subsetof @.ntpServers))].ntpServers";
JsonPath jsonPath = JsonPath.compile(path);

ctx.read(jsonPath);
}

//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
@Test
public void issue_620_1(){
String json = "{\n" +
" \"complexText\": {\n" +
" \"nestedFields\": [\n" +
" {\n" +
" \"index\": \"0\",\n" +
" \"name\": \"A\"\n" +
" },\n" +
" {\n" +
" \"index\": \"1\",\n" +
" \"name\": \"B\"\n" +
" },\n" +
" {\n" +
" \"index\": \"2\",\n" +
" \"name\": \"C\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";

String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," +
"$.complexText.nestedFields[?(@.index == '1')].name," +
"$.complexText.nestedFields[?(@.index == '0')].name)";
String path2 = "$.concat($.complexText.nestedFields[2].name," +
"$.complexText.nestedFields[1].name," +
"$.complexText.nestedFields[0].name)";

assertThat((String)JsonPath.read(json,path1)).isEqualTo("CBA");
assertThat((String)JsonPath.read(json,path2)).isEqualTo("CBA");
}
//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
@Test
public void issue_620_2(){
String json = "{\n" +
" \"complexText\": {\n" +
" \"nestedFields\": [\n" +
" {\n" +
" \"index\": \"0\",\n" +
" \"name\": \"A\"\n" +
" },\n" +
" {\n" +
" \"index\": \"1\",\n" +
" \"name\": \"B\"\n" +
" },\n" +
" {\n" +
" \"index\": \"2\",\n" +
" \"name\": \"C\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";

String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," +
"$.complexText.nestedFields[?((@.index == '1')].name," +
"$.complexText.nestedFields[?(@.index == '0')].name)";

boolean thrown = false;

try {
Object result = (Object) JsonPath.read(json,path1);
} catch (Exception e) {
thrown = true;
}

assertTrue(thrown);
}
}