Try to reproduce #142; fix a minor problem with error reporting
diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
index 32e48a8..4d8067d 100644
--- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
+++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
@@ -1795,7 +1795,8 @@
}
// [JACKSON-69]: allow unquoted names if feature enabled:
if (!isEnabled(Feature.ALLOW_UNQUOTED_FIELD_NAMES)) {
- _reportUnexpectedChar(ch, "was expecting double-quote to start field name");
+ char c = (char) _decodeCharForError(ch);
+ _reportUnexpectedChar(c, "was expecting double-quote to start field name");
}
/* Also: note that although we use a different table here,
* it does NOT handle UTF-8 decoding. It'll just pass those
@@ -2943,8 +2944,8 @@
protected int _decodeCharForError(int firstByte) throws IOException
{
- int c = firstByte;
- if (c < 0) { // if >= 0, is ascii and fine as is
+ int c = firstByte & 0xFF;
+ if (c > 0x7F) { // if >= 0, is ascii and fine as is
int needed;
// Ok; if we end here, we got multi-byte combination
diff --git a/src/test/java/com/fasterxml/jackson/core/json/TestJsonParser.java b/src/test/java/com/fasterxml/jackson/core/json/TestJsonParser.java
index 388acc7..b4cb7a8 100644
--- a/src/test/java/com/fasterxml/jackson/core/json/TestJsonParser.java
+++ b/src/test/java/com/fasterxml/jackson/core/json/TestJsonParser.java
@@ -34,6 +34,35 @@
_testIntern(true, false, "b");
}
+ public void testHandlingOfInvalidSpaceBytes() throws Exception
+ {
+ _testHandlingOfInvalidSpace(true);
+ }
+
+ public void testHandlingOfInvalidSpaceChars() throws Exception
+ {
+ _testHandlingOfInvalidSpace(false);
+ }
+
+ // [#142]
+ private void _testHandlingOfInvalidSpace(boolean useStream) throws Exception
+ {
+ JsonFactory f = new JsonFactory();
+ final String JSON = "{ \u00A0 \"a\":1}";
+ JsonParser jp = useStream ?
+ createParserUsingStream(f, JSON, "UTF-8") : createParserUsingReader(f, JSON);
+ assertToken(JsonToken.START_OBJECT, jp.nextToken());
+ try {
+ jp.nextToken();
+ fail("Should have failed");
+ } catch (JsonParseException e) {
+ verifyException(e, "unexpected character");
+ // and correct error code
+ verifyException(e, "code 160");
+ }
+ jp.close();
+ }
+
public void testInterningWithReaders() throws Exception
{
_testIntern(false, true, "c");