Skip to content

Commit 9b1b551

Browse files
committed
more corrections for proper position reports in error messages
1 parent 5b0f7ae commit 9b1b551

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CDL.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ private static String getValue(JSONTokener x) throws JSONException {
7070
c = x.next();
7171
if (c == q) {
7272
//Handle escaped double-quote
73-
if(x.next() != '\"')
74-
{
75-
x.back();
73+
char nextC = x.next();
74+
if(nextC != '\"') {
75+
// if our quote was the end of the file, don't step
76+
if(nextC > 0) {
77+
x.back();
78+
}
7679
break;
7780
}
7881
}

JSONTokener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public char next() throws JSONException {
186186

187187
if (c <= 0) { // End of stream
188188
this.eof = true;
189-
c = 0;
189+
return 0;
190190
}
191191
}
192192
this.index += 1;
@@ -214,8 +214,11 @@ public char next() throws JSONException {
214214
public char next(char c) throws JSONException {
215215
char n = this.next();
216216
if (n != c) {
217-
throw this.syntaxError("Expected '" + c + "' and instead saw '" +
218-
n + "'");
217+
if(n > 0) {
218+
throw this.syntaxError("Expected '" + c + "' and instead saw '" +
219+
n + "'");
220+
}
221+
throw this.syntaxError("Expected '" + c + "' and instead saw ''");
219222
}
220223
return n;
221224
}

XMLTokener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public Object nextContent() throws JSONException {
102102
}
103103
sb = new StringBuilder();
104104
for (;;) {
105-
if (c == '<' || c == 0) {
105+
if (c == 0) {
106+
return sb.toString().trim();
107+
}
108+
if (c == '<' ) {
106109
back();
107110
return sb.toString().trim();
108111
}

0 commit comments

Comments
 (0)