Fix testStringEndingInSlash by fixing nextNonWhitespace to always return the character at buffer[pos-1].
This commit is contained in:
parent
2c8bec27d4
commit
15e7819e9a
|
@ -863,6 +863,12 @@ public class JsonReader implements Closeable {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next character in the stream that is neither whitespace nor a
|
||||||
|
* part of a comment. When this returns, the returned character is always at
|
||||||
|
* {@code buffer[pos-1]}; this means the caller can always push back the
|
||||||
|
* returned character by decrementing {@code pos}.
|
||||||
|
*/
|
||||||
private int nextNonWhitespace(boolean throwOnEof) throws IOException {
|
private int nextNonWhitespace(boolean throwOnEof) throws IOException {
|
||||||
/*
|
/*
|
||||||
* This code uses ugly local variables 'p' and 'l' representing the 'pos'
|
* This code uses ugly local variables 'p' and 'l' representing the 'pos'
|
||||||
|
@ -895,9 +901,14 @@ public class JsonReader implements Closeable {
|
||||||
|
|
||||||
case '/':
|
case '/':
|
||||||
pos = p;
|
pos = p;
|
||||||
if (p == l && !fillBuffer(1)) {
|
if (p == l) {
|
||||||
|
pos--; // push back '/' so it's still in the buffer when this method returns
|
||||||
|
boolean charsLoaded = fillBuffer(2);
|
||||||
|
pos++; // consume the '/' again
|
||||||
|
if (!charsLoaded) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checkLenient();
|
checkLenient();
|
||||||
char peek = buffer[pos];
|
char peek = buffer[pos];
|
||||||
|
|
|
@ -1092,7 +1092,21 @@ public final class JsonReaderTest extends TestCase {
|
||||||
public void testStringEndingInSlash() throws IOException {
|
public void testStringEndingInSlash() throws IOException {
|
||||||
JsonReader reader = new JsonReader(new StringReader("/"));
|
JsonReader reader = new JsonReader(new StringReader("/"));
|
||||||
reader.setLenient(true);
|
reader.setLenient(true);
|
||||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
try {
|
||||||
|
reader.peek();
|
||||||
|
fail();
|
||||||
|
} catch (MalformedJsonException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDocumentWithCommentEndingInSlash() throws IOException {
|
||||||
|
JsonReader reader = new JsonReader(new StringReader("/* foo *//"));
|
||||||
|
reader.setLenient(true);
|
||||||
|
try {
|
||||||
|
reader.peek();
|
||||||
|
fail();
|
||||||
|
} catch (MalformedJsonException expected) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringWithLeadingSlash() throws IOException {
|
public void testStringWithLeadingSlash() throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user