Skip to content

Commit

Permalink
Fixed issue FasterXML#603
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Renaud committed Feb 25, 2020
1 parent 7fe4494 commit 8556ca6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
Expand Up @@ -221,9 +221,6 @@ protected boolean _loadMore() throws IOException
if (_reader != null) {
int count = _reader.read(_inputBuffer, 0, _inputBuffer.length);
if (count > 0) {
_inputPtr = 0;
_inputEnd = count;

_currInputProcessed += bufSize;
_currInputRowStart -= bufSize;

Expand All @@ -232,6 +229,9 @@ protected boolean _loadMore() throws IOException
// in negative value, which is fine as combine value remains unchanged.
_nameStartOffset -= bufSize;

_inputPtr = 0;
_inputEnd = count;

return true;
}
// End of input
Expand Down
Expand Up @@ -193,9 +193,6 @@ protected final boolean _loadMore() throws IOException

int count = _inputStream.read(_inputBuffer, 0, space);
if (count > 0) {
_inputPtr = 0;
_inputEnd = count;

_currInputProcessed += _inputEnd;
_currInputRowStart -= _inputEnd;

Expand All @@ -204,6 +201,9 @@ protected final boolean _loadMore() throws IOException
// in negative value, which is fine as combine value remains unchanged.
_nameStartOffset -= bufSize;

_inputPtr = 0;
_inputEnd = count;

return true;
}
// End of input
Expand Down
Expand Up @@ -3,6 +3,11 @@
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonFactory;

import java.io.IOException;
import java.util.Base64;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class LocationOffsetsTest extends com.fasterxml.jackson.core.BaseTest
{
final JsonFactory JSON_F = new JsonFactory();
Expand Down Expand Up @@ -143,7 +148,7 @@ private void _testWithLazyStringRead(int readMode) throws Exception
assertEquals(8, p.getCurrentLocation().getColumnNr());
p.close();
}

// for [core#533]
public void testUtf8Bom() throws Exception
{
Expand Down Expand Up @@ -232,4 +237,65 @@ private byte[] withUtf8Bom(byte[] bytes) {
System.arraycopy(bytes, 0, arr, 3, bytes.length);
return arr;
}

public void testBigPayload() throws IOException {
JsonLocation loc;
JsonParser p;

byte[] bytes = new byte[50_000];
ThreadLocalRandom.current().nextBytes(bytes);
String b64Encoded = Base64.getEncoder().encodeToString(bytes);

String doc = "{\"key\":\"" + b64Encoded + "\"}";

p = createParserUsingStream(JSON_F, doc, "UTF-8");

assertToken(JsonToken.START_OBJECT, p.nextToken());
loc = p.getTokenLocation();
assertEquals(0, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(1, loc.getColumnNr());
loc = p.getCurrentLocation();
assertEquals(1, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(2, loc.getColumnNr());

assertToken(JsonToken.FIELD_NAME, p.nextToken());
loc = p.getTokenLocation();
assertEquals(1, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(2, loc.getColumnNr());
loc = p.getCurrentLocation();
assertEquals(8, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(9, loc.getColumnNr());

assertToken(JsonToken.VALUE_STRING, p.nextToken());
loc = p.getTokenLocation();
assertEquals(7, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(8, loc.getColumnNr());
loc = p.getCurrentLocation();
assertEquals(8, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(9, loc.getColumnNr());

p.getTextCharacters();
loc = p.getTokenLocation();
assertEquals(7, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(8, loc.getColumnNr());
loc = p.getCurrentLocation();
assertEquals(doc.length() - 1, loc.getByteOffset());
assertEquals(-1L, loc.getCharOffset());
assertEquals(1, loc.getLineNr());
assertEquals(doc.length(), loc.getColumnNr());
}
}

0 comments on commit 8556ca6

Please sign in to comment.