Skip to content

Commit

Permalink
One more fix for #157, this time for negative-number parsing branch (…
Browse files Browse the repository at this point in the history
…which is different from pos)
  • Loading branch information
cowtowncoder committed Oct 14, 2014
1 parent d860a8c commit a37f08e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ protected JsonToken _parseNegNumber() throws IOException

// And then figure out how far we can read without further checks
// for either input or output
int end = _inputPtr + outBuf.length;
int end = _inputPtr + outBuf.length - outPtr;
if (end > _inputEnd) {
end = _inputEnd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,32 @@ private void _testLongNumbers(JsonFactory f, String num, boolean useStream) thro
assertToken(JsonToken.END_ARRAY, jp.nextToken());
}

// and alternate take on for #157 (with negative num)
public void testLongNumbers2() throws Exception
{
StringBuilder input = new StringBuilder();
// test this with negative
input.append('-');
for (int i = 0; i < 2100; i++) {
input.append(1);
}
final String DOC = input.toString();
JsonFactory f = new JsonFactory();
_testIssue160LongNumbers(f, DOC, false);
_testIssue160LongNumbers(f, DOC, true);
}

private void _testIssue160LongNumbers(JsonFactory f, String doc, boolean useStream) throws Exception
{
JsonParser jp = useStream
? FACTORY.createParser(doc.getBytes("UTF-8"))
: FACTORY.createParser(doc);
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
BigInteger v = jp.getBigIntegerValue();
assertNull(jp.nextToken());
assertEquals(doc, v.toString());
}

/*
/**********************************************************
/* Tests for invalid access
Expand Down

0 comments on commit a37f08e

Please sign in to comment.