Skip to content

Commit 6e984e2

Browse files
committed
adding testcases to cover situations where the input upwards step count is zero
1 parent 8001bcd commit 6e984e2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

core/src/main/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ private char curr() {
6262
}
6363

6464
private void parseUpwardsStepCount() throws ParseException {
65-
if (!isDigit(curr()) || curr() == '0') {
65+
if (!isDigit(curr())) {
6666
fail();
67+
} else if (curr() == '0') {
68+
next();
69+
if (curr() == '/' || curr() == '#' || curr() == EOF) {
70+
pos--;
71+
} else {
72+
fail();
73+
}
6774
}
6875
for (char current = next(); isDigit(current) && pos < input.length(); current = next())
6976
;

core/src/test/java/org/everit/json/schema/internal/RelativeJsonPointerFormatValidatorTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,22 @@ public void noUpwardsStepCount() {
7676
}
7777

7878
@Test
79-
public void leadingZeroFailure() {
79+
public void leadingZeroFailure() {
8080
assertFailure("0123", SUBJECT, "[0123] is not a valid relative JSON Pointer");
8181
}
82+
83+
@Test
84+
public void onlyLeadingZero() {
85+
assertSuccess("0", SUBJECT);
86+
}
87+
88+
@Test
89+
public void upwardsStepCountIsZeroFollowedByPointer() {
90+
assertSuccess("0/a/b", SUBJECT);
91+
}
92+
93+
@Test
94+
public void upwardsStepCountIsZeroFollowedByHashmark() {
95+
assertSuccess("0#", SUBJECT);
96+
}
8297
}

0 commit comments

Comments
 (0)