Skip to content

Commit 993d66a

Browse files
authored
Fixed issue #603 (#604)
Fixed issue #603 (location offset regression in 2.10.1)
1 parent 7fe4494 commit 993d66a

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ protected boolean _loadMore() throws IOException
221221
if (_reader != null) {
222222
int count = _reader.read(_inputBuffer, 0, _inputBuffer.length);
223223
if (count > 0) {
224-
_inputPtr = 0;
225-
_inputEnd = count;
226-
227224
_currInputProcessed += bufSize;
228225
_currInputRowStart -= bufSize;
229226

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

232+
_inputPtr = 0;
233+
_inputEnd = count;
234+
235235
return true;
236236
}
237237
// End of input

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ protected final boolean _loadMore() throws IOException
193193

194194
int count = _inputStream.read(_inputBuffer, 0, space);
195195
if (count > 0) {
196-
_inputPtr = 0;
197-
_inputEnd = count;
198-
199196
_currInputProcessed += _inputEnd;
200197
_currInputRowStart -= _inputEnd;
201198

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

204+
_inputPtr = 0;
205+
_inputEnd = count;
206+
207207
return true;
208208
}
209209
// End of input

src/test/java/com/fasterxml/jackson/core/read/LocationOffsetsTest.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.fasterxml.jackson.core.*;
44
import com.fasterxml.jackson.core.json.JsonFactory;
55

6+
import java.io.IOException;
7+
import java.util.Random;
8+
69
public class LocationOffsetsTest extends com.fasterxml.jackson.core.BaseTest
710
{
811
final JsonFactory JSON_F = new JsonFactory();
@@ -143,7 +146,7 @@ private void _testWithLazyStringRead(int readMode) throws Exception
143146
assertEquals(8, p.getCurrentLocation().getColumnNr());
144147
p.close();
145148
}
146-
149+
147150
// for [core#533]
148151
public void testUtf8Bom() throws Exception
149152
{
@@ -232,4 +235,72 @@ private byte[] withUtf8Bom(byte[] bytes) {
232235
System.arraycopy(bytes, 0, arr, 3, bytes.length);
233236
return arr;
234237
}
238+
239+
public void testBigPayload() throws IOException {
240+
JsonLocation loc;
241+
JsonParser p;
242+
243+
String doc = "{\"key\":\"" + generateRandomAlpha(50000) + "\"}";
244+
245+
p = createParserUsingStream(JSON_F, doc, "UTF-8");
246+
247+
assertToken(JsonToken.START_OBJECT, p.nextToken());
248+
loc = p.getTokenLocation();
249+
assertEquals(0, loc.getByteOffset());
250+
assertEquals(-1L, loc.getCharOffset());
251+
assertEquals(1, loc.getLineNr());
252+
assertEquals(1, loc.getColumnNr());
253+
loc = p.getCurrentLocation();
254+
assertEquals(1, loc.getByteOffset());
255+
assertEquals(-1L, loc.getCharOffset());
256+
assertEquals(1, loc.getLineNr());
257+
assertEquals(2, loc.getColumnNr());
258+
259+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
260+
loc = p.getTokenLocation();
261+
assertEquals(1, loc.getByteOffset());
262+
assertEquals(-1L, loc.getCharOffset());
263+
assertEquals(1, loc.getLineNr());
264+
assertEquals(2, loc.getColumnNr());
265+
loc = p.getCurrentLocation();
266+
assertEquals(8, loc.getByteOffset());
267+
assertEquals(-1L, loc.getCharOffset());
268+
assertEquals(1, loc.getLineNr());
269+
assertEquals(9, loc.getColumnNr());
270+
271+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
272+
loc = p.getTokenLocation();
273+
assertEquals(7, loc.getByteOffset());
274+
assertEquals(-1L, loc.getCharOffset());
275+
assertEquals(1, loc.getLineNr());
276+
assertEquals(8, loc.getColumnNr());
277+
loc = p.getCurrentLocation();
278+
assertEquals(8, loc.getByteOffset());
279+
assertEquals(-1L, loc.getCharOffset());
280+
assertEquals(1, loc.getLineNr());
281+
assertEquals(9, loc.getColumnNr());
282+
283+
p.getTextCharacters();
284+
loc = p.getTokenLocation();
285+
assertEquals(7, loc.getByteOffset());
286+
assertEquals(-1L, loc.getCharOffset());
287+
assertEquals(1, loc.getLineNr());
288+
assertEquals(8, loc.getColumnNr());
289+
loc = p.getCurrentLocation();
290+
assertEquals(doc.length() - 1, loc.getByteOffset());
291+
assertEquals(-1L, loc.getCharOffset());
292+
assertEquals(1, loc.getLineNr());
293+
assertEquals(doc.length(), loc.getColumnNr());
294+
}
295+
296+
private String generateRandomAlpha(int length) {
297+
StringBuilder sb = new StringBuilder(length);
298+
Random rnd = new Random(length);
299+
for (int i = 0; i < length; ++i) {
300+
// let's limit it not to include surrogate pairs:
301+
char ch = (char) ('A' + rnd.nextInt(26));
302+
sb.append(ch);
303+
}
304+
return sb.toString();
305+
}
235306
}

0 commit comments

Comments
 (0)