Loading core/java/android/util/JsonReader.java +8 −0 Original line number Diff line number Diff line Loading @@ -738,6 +738,14 @@ public final class JsonReader implements Closeable { int total; while ((total = in.read(buffer, limit, buffer.length - limit)) != -1) { limit += total; // if this is the first read, consume an optional byte order mark (BOM) if it exists if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 0 && buffer[0] == '\ufeff') { pos++; bufferStartColumn--; } if (limit >= minimum) { return true; } Loading core/tests/coretests/src/android/util/JsonReaderTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -857,11 +857,32 @@ public final class JsonReaderTest extends TestCase { } } public void testBomIgnoredAsFirstCharacterOfDocument() throws IOException { JsonReader reader = new JsonReader(new StringReader("\ufeff[]")); reader.beginArray(); reader.endArray(); } public void testBomForbiddenAsOtherCharacterInDocument() throws IOException { JsonReader reader = new JsonReader(new StringReader("[\ufeff]")); reader.beginArray(); try { reader.endArray(); fail(); } catch (IOException expected) { } } public void testFailWithPosition() throws IOException { testFailWithPosition("Expected literal value at line 6 column 3", "[\n\n\n\n\n0,}]"); } public void testFailWithPositionIsOffsetByBom() throws IOException { testFailWithPosition("Expected literal value at line 1 column 4", "\ufeff[0,}]"); } public void testFailWithPositionGreaterThanBufferSize() throws IOException { String spaces = repeat(' ', 8192); testFailWithPosition("Expected literal value at line 6 column 3", Loading Loading
core/java/android/util/JsonReader.java +8 −0 Original line number Diff line number Diff line Loading @@ -738,6 +738,14 @@ public final class JsonReader implements Closeable { int total; while ((total = in.read(buffer, limit, buffer.length - limit)) != -1) { limit += total; // if this is the first read, consume an optional byte order mark (BOM) if it exists if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 0 && buffer[0] == '\ufeff') { pos++; bufferStartColumn--; } if (limit >= minimum) { return true; } Loading
core/tests/coretests/src/android/util/JsonReaderTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -857,11 +857,32 @@ public final class JsonReaderTest extends TestCase { } } public void testBomIgnoredAsFirstCharacterOfDocument() throws IOException { JsonReader reader = new JsonReader(new StringReader("\ufeff[]")); reader.beginArray(); reader.endArray(); } public void testBomForbiddenAsOtherCharacterInDocument() throws IOException { JsonReader reader = new JsonReader(new StringReader("[\ufeff]")); reader.beginArray(); try { reader.endArray(); fail(); } catch (IOException expected) { } } public void testFailWithPosition() throws IOException { testFailWithPosition("Expected literal value at line 6 column 3", "[\n\n\n\n\n0,}]"); } public void testFailWithPositionIsOffsetByBom() throws IOException { testFailWithPosition("Expected literal value at line 1 column 4", "\ufeff[0,}]"); } public void testFailWithPositionGreaterThanBufferSize() throws IOException { String spaces = repeat(' ', 8192); testFailWithPosition("Expected literal value at line 6 column 3", Loading