Skip to content

Commit a2b3d2e

Browse files
committed
Fix #51
1 parent f52abd9 commit a2b3d2e

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ Damian Servin (Qnzvna@github)
120120
* Contributed #195 (csv) Adds schema creating csv schema with View
121121
(2.11.0)
122122

123+
Rob Spoor (robtimus@github)
124+
* Reported #51: (yaml) `YAMLParser._locationFor()` does not use index available from
125+
`Mark`object of Event
126+
(2.11.1)

release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Project: jackson-datatypes-text
1010

1111
2.11.1 (not yet released)
1212

13-
-
13+
#51: (yaml) `YAMLParser._locationFor()` does not use index available from `Mark`
14+
object of Event
15+
(reported by Rob S)
1416

1517
2.11.0 (26-Apr-2020)
1618

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ protected JsonLocation _locationFor(Mark m)
326326
-1, -1, -1);
327327
}
328328
return new JsonLocation(_ioContext.getSourceReference(),
329-
-1,
329+
m.getIndex(),
330330
m.getLine() + 1, // from 0- to 1-based
331331
m.getColumn() + 1); // ditto
332332
}

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingParseTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.yaml.deser;
22

3+
import com.fasterxml.jackson.core.JsonLocation;
34
import com.fasterxml.jackson.core.JsonParser;
45
import com.fasterxml.jackson.core.JsonToken;
56
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
@@ -33,9 +34,21 @@ public void testBasic() throws Exception
3334
assertToken(JsonToken.FIELD_NAME, p.nextToken());
3435
assertToken(JsonToken.VALUE_STRING, p.nextToken());
3536
assertEquals("text", p.getText());
37+
JsonLocation loc = p.getTokenLocation();
38+
assertEquals(1, loc.getLineNr());
39+
assertEquals(9, loc.getColumnNr());
40+
assertEquals(8, loc.getCharOffset());
41+
assertEquals(-1, loc.getByteOffset());
42+
3643
assertToken(JsonToken.FIELD_NAME, p.nextToken());
3744
assertToken(JsonToken.VALUE_TRUE, p.nextToken());
3845
assertEquals("true", p.getText());
46+
loc = p.getTokenLocation();
47+
assertEquals(2, loc.getLineNr());
48+
assertEquals(7, loc.getColumnNr());
49+
assertEquals(21, loc.getCharOffset());
50+
assertEquals(-1, loc.getByteOffset());
51+
3952
assertToken(JsonToken.FIELD_NAME, p.nextToken());
4053
assertToken(JsonToken.VALUE_FALSE, p.nextToken());
4154
assertEquals("false", p.getText());

0 commit comments

Comments
 (0)