Skip to content

Commit

Permalink
Check for the existence of the next significant bracket (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
twobiers authored Jan 18, 2024
1 parent 900ebfe commit 71a09c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,11 @@ private boolean readBracketPropertyToken(PathTokenAppender appender) {
fail("Property has not been closed - missing closing " + potentialStringDelimiter);
}

int endBracketIndex = path.indexOfNextSignificantChar(endPosition, CLOSE_SQUARE_BRACKET) + 1;
int endBracketIndex = path.indexOfNextSignificantChar(endPosition, CLOSE_SQUARE_BRACKET);
if(endBracketIndex == -1) {
fail("Property has not been closed - missing closing ]");
}
endBracketIndex++;

path.setPosition(endBracketIndex);

Expand Down
12 changes: 12 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/Issue_970.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jayway.jsonpath;

import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThatNoException;

public class Issue_970 {
@Test
public void shouldNotCauseStackOverflow() {
assertThatNoException().isThrownBy(() -> Criteria.where("[']',"));
}
}
12 changes: 12 additions & 0 deletions json-path/src/test/java/com/jayway/jsonpath/Issue_973.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jayway.jsonpath;

import org.junit.Test;

import static org.assertj.core.api.Assertions.*;

public class Issue_973 {
@Test
public void shouldNotCauseStackOverflow() {
assertThatNoException().isThrownBy(() -> Criteria.parse("@[\"\",/\\"));
}
}

0 comments on commit 71a09c1

Please sign in to comment.