Skip to content

Commit a37f08e

Browse files
committed
One more fix for #157, this time for negative-number parsing branch (which is different from pos)
1 parent d860a8c commit a37f08e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ protected JsonToken _parseNegNumber() throws IOException
12561256

12571257
// And then figure out how far we can read without further checks
12581258
// for either input or output
1259-
int end = _inputPtr + outBuf.length;
1259+
int end = _inputPtr + outBuf.length - outPtr;
12601260
if (end > _inputEnd) {
12611261
end = _inputEnd;
12621262
}

src/test/java/com/fasterxml/jackson/core/json/TestNumericValues.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,32 @@ private void _testLongNumbers(JsonFactory f, String num, boolean useStream) thro
447447
assertToken(JsonToken.END_ARRAY, jp.nextToken());
448448
}
449449

450+
// and alternate take on for #157 (with negative num)
451+
public void testLongNumbers2() throws Exception
452+
{
453+
StringBuilder input = new StringBuilder();
454+
// test this with negative
455+
input.append('-');
456+
for (int i = 0; i < 2100; i++) {
457+
input.append(1);
458+
}
459+
final String DOC = input.toString();
460+
JsonFactory f = new JsonFactory();
461+
_testIssue160LongNumbers(f, DOC, false);
462+
_testIssue160LongNumbers(f, DOC, true);
463+
}
464+
465+
private void _testIssue160LongNumbers(JsonFactory f, String doc, boolean useStream) throws Exception
466+
{
467+
JsonParser jp = useStream
468+
? FACTORY.createParser(doc.getBytes("UTF-8"))
469+
: FACTORY.createParser(doc);
470+
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
471+
BigInteger v = jp.getBigIntegerValue();
472+
assertNull(jp.nextToken());
473+
assertEquals(doc, v.toString());
474+
}
475+
450476
/*
451477
/**********************************************************
452478
/* Tests for invalid access

0 commit comments

Comments
 (0)