Skip to content

Commit

Permalink
Fix FasterXML#176 for 2.4(.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 31, 2014
1 parent 0d9cd9f commit d999514
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ json-specificity (naming due to historical reasons).
(reported by Lars P, larsp@github)
#173: An exception is thrown for a valid JsonPointer expression
(reported by Alex S)

#176: `JsonPointer` should not consider "00" to be valid index
(reported by fge@gitub)
- Fix `JsonGenerator.setFeatureMask()` to better handle dynamic changes.

2.4.3 (02-Oct-2014)
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/fasterxml/jackson/core/JsonPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,21 @@ public JsonPointer tail() {

private final static int _parseIndex(String str) {
final int len = str.length();
// [Issue#133]: beware of super long indexes; assume we never
// [core#133]: beware of super long indexes; assume we never
// have arrays over 2 billion entries so ints are fine.
if (len == 0 || len > 10) {
return -1;
}
for (int i = 0; i < len; ++i) {
char c = str.charAt(i);
// [core#176]: no leading zeroes allowed
char c = str.charAt(0);
if (c <= '0') {
return (len == 1 && c == '0') ? 0 : -1;
}
if (c > '9') {
return -1;
}
for (int i = 1; i < len; ++i) {
c = str.charAt(i);
if (c > '9' || c < '0') {
return -1;
}
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/com/fasterxml/jackson/core/TestJsonPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public void testWonkyNumber173() throws Exception
JsonPointer ptr = JsonPointer.compile("/1e0");
assertFalse(ptr.matches());
}


// [core#176]: do not allow leading zeroes
public void testIZeroIndex() throws Exception
{
JsonPointer ptr = JsonPointer.compile("/0");
assertEquals(0, ptr.getMatchingIndex());
ptr = JsonPointer.compile("/00");
assertEquals(-1, ptr.getMatchingIndex());
}

public void testQuotedPath() throws Exception
{
final String INPUT = "/w~1out/til~0de/a~1b";
Expand Down

0 comments on commit d999514

Please sign in to comment.