Skip to content

Commit

Permalink
fix(parser): Fix indices of self-closing tags in XML (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Sep 11, 2021
1 parent 317aaaa commit 3287ef2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/Parser.ts
Expand Up @@ -356,6 +356,9 @@ export class Parser {
this.foreignContext[this.foreignContext.length - 1]
) {
this.closeCurrentTag(false);

// Set `startIndex` for next node
this.startIndex = this.endIndex + 1;
} else {
// Ignore the fact that the tag is self-closing.
this.onopentagend();
Expand Down
4 changes: 2 additions & 2 deletions src/__fixtures__/Events/13-long-cdata-end.json
Expand Up @@ -27,13 +27,13 @@
},
{
"event": "opentagname",
"startIndex": 0,
"startIndex": 10,
"endIndex": 14,
"data": ["tag"]
},
{
"event": "opentag",
"startIndex": 0,
"startIndex": 10,
"endIndex": 14,
"data": ["tag", {}, false]
},
Expand Down
65 changes: 65 additions & 0 deletions src/__fixtures__/Events/45-self-closing-indices.json
@@ -0,0 +1,65 @@
{
"name": "Self-closing indices (#941)",
"options": {
"parser": {
"xmlMode": true
}
},
"input": "<xml><a/><b/></xml>",
"expected": [
{
"event": "opentagname",
"data": ["xml"],
"startIndex": 0,
"endIndex": 4
},
{
"event": "opentag",
"data": ["xml", {}, false],
"startIndex": 0,
"endIndex": 4
},
{
"event": "opentagname",
"data": ["a"],
"startIndex": 5,
"endIndex": 7
},
{
"event": "opentag",
"data": ["a", {}, false],
"startIndex": 5,
"endIndex": 8
},
{
"event": "closetag",
"data": ["a", true],
"startIndex": 5,
"endIndex": 8
},
{
"event": "opentagname",
"data": ["b"],
"startIndex": 9,
"endIndex": 11
},
{
"event": "opentag",
"data": ["b", {}, false],
"startIndex": 9,
"endIndex": 12
},
{
"event": "closetag",
"data": ["b", true],
"startIndex": 9,
"endIndex": 12
},
{
"event": "closetag",
"data": ["xml", false],
"startIndex": 13,
"endIndex": 18
}
]
}
24 changes: 12 additions & 12 deletions src/__snapshots__/WritableStream.spec.ts.snap
Expand Up @@ -227,7 +227,7 @@ Array [
],
"endIndex": 256,
"event": "text",
"startIndex": 204,
"startIndex": 255,
},
Object {
"data": Array [
Expand Down Expand Up @@ -275,7 +275,7 @@ Array [
],
"endIndex": 293,
"event": "text",
"startIndex": 257,
"startIndex": 292,
},
Object {
"data": Array [
Expand Down Expand Up @@ -616,7 +616,7 @@ Array [
],
"endIndex": 584,
"event": "text",
"startIndex": 530,
"startIndex": 582,
},
Object {
"data": Array [
Expand Down Expand Up @@ -686,7 +686,7 @@ Array [
],
"endIndex": 676,
"event": "text",
"startIndex": 585,
"startIndex": 674,
},
Object {
"data": Array [
Expand Down Expand Up @@ -745,7 +745,7 @@ Array [
],
"endIndex": 746,
"event": "text",
"startIndex": 677,
"startIndex": 744,
},
Object {
"data": Array [
Expand Down Expand Up @@ -972,7 +972,7 @@ Array [
],
"endIndex": 919,
"event": "text",
"startIndex": 910,
"startIndex": 918,
},
Object {
"data": Array [
Expand Down Expand Up @@ -1911,7 +1911,7 @@ Array [
],
"endIndex": 657,
"event": "text",
"startIndex": 641,
"startIndex": 655,
},
Object {
"data": Array [
Expand Down Expand Up @@ -2453,7 +2453,7 @@ Array [
],
"endIndex": 1257,
"event": "text",
"startIndex": 1187,
"startIndex": 1254,
},
Object {
"data": Array [
Expand Down Expand Up @@ -5191,7 +5191,7 @@ Array [
],
"endIndex": 2669,
"event": "text",
"startIndex": 2575,
"startIndex": 2663,
},
Object {
"data": Array [
Expand Down Expand Up @@ -5543,7 +5543,7 @@ Array [
],
"endIndex": 206,
"event": "text",
"startIndex": 193,
"startIndex": 204,
},
Object {
"data": Array [
Expand Down Expand Up @@ -5579,7 +5579,7 @@ Array [
],
"endIndex": 220,
"event": "text",
"startIndex": 207,
"startIndex": 218,
},
Object {
"data": Array [
Expand Down Expand Up @@ -5713,7 +5713,7 @@ Array [
],
"endIndex": 274,
"event": "text",
"startIndex": 260,
"startIndex": 271,
},
Object {
"data": Array [
Expand Down

0 comments on commit 3287ef2

Please sign in to comment.