Skip to content

Commit 10e5038

Browse files
authored
Update AsyncNonStandardNumberParsingTest.java (#789)
1 parent e9d80f0 commit 10e5038

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStandardNumberParsingTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,65 @@ public void testDoubleMarker() throws Exception
9999
}
100100
*/
101101

102+
/**
103+
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
104+
*/
105+
public void testLeadingDotInDecimal() throws Exception {
106+
final String JSON = "[ .123 ]";
107+
108+
// without enabling, should get an exception
109+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
110+
assertToken(JsonToken.START_ARRAY, p.nextToken());
111+
try {
112+
p.nextToken();
113+
fail("Expected exception");
114+
} catch (Exception e) {
115+
verifyException(e, "Unexpected character ('.'");
116+
} finally {
117+
p.close();
118+
}
119+
}
120+
121+
/*
122+
* The format "+NNN" (as opposed to "NNN") is not valid JSON, so this should fail
123+
*/
124+
public void testLeadingPlusSignInDecimalDefaultFail() throws Exception {
125+
final String JSON = "[ +123 ]";
126+
127+
// without enabling, should get an exception
128+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
129+
assertToken(JsonToken.START_ARRAY, p.nextToken());
130+
try {
131+
p.nextToken();
132+
fail("Expected exception");
133+
} catch (Exception e) {
134+
//the message does not match non-async parsers
135+
verifyException(e, "Unrecognized token '+123'");
136+
} finally {
137+
p.close();
138+
}
139+
}
140+
141+
/**
142+
* The format "NNN." (as opposed to "NNN") is not valid JSON, so this should fail
143+
*/
144+
public void testTrailingDotInDecimal() throws Exception {
145+
final String JSON = "[ 123. ]";
146+
147+
// without enabling, should get an exception
148+
AsyncReaderWrapper p = createParser(DEFAULT_F, JSON, 1);
149+
assertToken(JsonToken.START_ARRAY, p.nextToken());
150+
try {
151+
p.nextToken();
152+
fail("Expected exception");
153+
} catch (Exception e) {
154+
//the message does not match non-async parsers
155+
verifyException(e, "Unexpected character (' '");
156+
} finally {
157+
p.close();
158+
}
159+
}
160+
102161
private AsyncReaderWrapper createParser(JsonFactory f, String doc, int readBytes) throws IOException
103162
{
104163
return asyncForBytes(f, readBytes, _jsonDoc(doc), 1);

0 commit comments

Comments
 (0)