Skip to content

Commit 3287ef2

Browse files
authored
fix(parser): Fix indices of self-closing tags in XML (#949)
1 parent 317aaaa commit 3287ef2

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

src/Parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ export class Parser {
356356
this.foreignContext[this.foreignContext.length - 1]
357357
) {
358358
this.closeCurrentTag(false);
359+
360+
// Set `startIndex` for next node
361+
this.startIndex = this.endIndex + 1;
359362
} else {
360363
// Ignore the fact that the tag is self-closing.
361364
this.onopentagend();

src/__fixtures__/Events/13-long-cdata-end.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
},
2828
{
2929
"event": "opentagname",
30-
"startIndex": 0,
30+
"startIndex": 10,
3131
"endIndex": 14,
3232
"data": ["tag"]
3333
},
3434
{
3535
"event": "opentag",
36-
"startIndex": 0,
36+
"startIndex": 10,
3737
"endIndex": 14,
3838
"data": ["tag", {}, false]
3939
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "Self-closing indices (#941)",
3+
"options": {
4+
"parser": {
5+
"xmlMode": true
6+
}
7+
},
8+
"input": "<xml><a/><b/></xml>",
9+
"expected": [
10+
{
11+
"event": "opentagname",
12+
"data": ["xml"],
13+
"startIndex": 0,
14+
"endIndex": 4
15+
},
16+
{
17+
"event": "opentag",
18+
"data": ["xml", {}, false],
19+
"startIndex": 0,
20+
"endIndex": 4
21+
},
22+
{
23+
"event": "opentagname",
24+
"data": ["a"],
25+
"startIndex": 5,
26+
"endIndex": 7
27+
},
28+
{
29+
"event": "opentag",
30+
"data": ["a", {}, false],
31+
"startIndex": 5,
32+
"endIndex": 8
33+
},
34+
{
35+
"event": "closetag",
36+
"data": ["a", true],
37+
"startIndex": 5,
38+
"endIndex": 8
39+
},
40+
{
41+
"event": "opentagname",
42+
"data": ["b"],
43+
"startIndex": 9,
44+
"endIndex": 11
45+
},
46+
{
47+
"event": "opentag",
48+
"data": ["b", {}, false],
49+
"startIndex": 9,
50+
"endIndex": 12
51+
},
52+
{
53+
"event": "closetag",
54+
"data": ["b", true],
55+
"startIndex": 9,
56+
"endIndex": 12
57+
},
58+
{
59+
"event": "closetag",
60+
"data": ["xml", false],
61+
"startIndex": 13,
62+
"endIndex": 18
63+
}
64+
]
65+
}

src/__snapshots__/WritableStream.spec.ts.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Array [
227227
],
228228
"endIndex": 256,
229229
"event": "text",
230-
"startIndex": 204,
230+
"startIndex": 255,
231231
},
232232
Object {
233233
"data": Array [
@@ -275,7 +275,7 @@ Array [
275275
],
276276
"endIndex": 293,
277277
"event": "text",
278-
"startIndex": 257,
278+
"startIndex": 292,
279279
},
280280
Object {
281281
"data": Array [
@@ -616,7 +616,7 @@ Array [
616616
],
617617
"endIndex": 584,
618618
"event": "text",
619-
"startIndex": 530,
619+
"startIndex": 582,
620620
},
621621
Object {
622622
"data": Array [
@@ -686,7 +686,7 @@ Array [
686686
],
687687
"endIndex": 676,
688688
"event": "text",
689-
"startIndex": 585,
689+
"startIndex": 674,
690690
},
691691
Object {
692692
"data": Array [
@@ -745,7 +745,7 @@ Array [
745745
],
746746
"endIndex": 746,
747747
"event": "text",
748-
"startIndex": 677,
748+
"startIndex": 744,
749749
},
750750
Object {
751751
"data": Array [
@@ -972,7 +972,7 @@ Array [
972972
],
973973
"endIndex": 919,
974974
"event": "text",
975-
"startIndex": 910,
975+
"startIndex": 918,
976976
},
977977
Object {
978978
"data": Array [
@@ -1911,7 +1911,7 @@ Array [
19111911
],
19121912
"endIndex": 657,
19131913
"event": "text",
1914-
"startIndex": 641,
1914+
"startIndex": 655,
19151915
},
19161916
Object {
19171917
"data": Array [
@@ -2453,7 +2453,7 @@ Array [
24532453
],
24542454
"endIndex": 1257,
24552455
"event": "text",
2456-
"startIndex": 1187,
2456+
"startIndex": 1254,
24572457
},
24582458
Object {
24592459
"data": Array [
@@ -5191,7 +5191,7 @@ Array [
51915191
],
51925192
"endIndex": 2669,
51935193
"event": "text",
5194-
"startIndex": 2575,
5194+
"startIndex": 2663,
51955195
},
51965196
Object {
51975197
"data": Array [
@@ -5543,7 +5543,7 @@ Array [
55435543
],
55445544
"endIndex": 206,
55455545
"event": "text",
5546-
"startIndex": 193,
5546+
"startIndex": 204,
55475547
},
55485548
Object {
55495549
"data": Array [
@@ -5579,7 +5579,7 @@ Array [
55795579
],
55805580
"endIndex": 220,
55815581
"event": "text",
5582-
"startIndex": 207,
5582+
"startIndex": 218,
55835583
},
55845584
Object {
55855585
"data": Array [
@@ -5713,7 +5713,7 @@ Array [
57135713
],
57145714
"endIndex": 274,
57155715
"event": "text",
5716-
"startIndex": 260,
5716+
"startIndex": 271,
57175717
},
57185718
Object {
57195719
"data": Array [

0 commit comments

Comments
 (0)