Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): Fix endIndex of text events being off by 1 #932

Merged
merged 2 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class Parser {
/** @internal */
ontext(data: string): void {
const idx = this.tokenizer.getAbsoluteIndex();
this.endIndex = idx;
this.endIndex = idx - 1;
this.cbs.ontext?.(data);
this.startIndex = idx;
}
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/01-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
"event": "text",
"startIndex": 15,
"endIndex": 19,
"endIndex": 18,
"data": ["adsf"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/02-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"event": "text",
"startIndex": 32,
"endIndex": 49,
"endIndex": 48,
"data": ["<h1>Heading1</h1>"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/03-lowercase_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"event": "text",
"startIndex": 15,
"endIndex": 19,
"endIndex": 18,
"data": ["adsf"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/05-cdata-special.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 8,
"endIndex": 53,
"endIndex": 52,
"data": ["/*<![CDATA[*/ asdf ><asdf></adsf><> fo/*]]>*/"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/06-leading-lt.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 3,
"endIndex": 2,
"data": [">a>"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/07-self-closing.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
"event": "text",
"startIndex": 25,
"endIndex": 28,
"endIndex": 27,
"data": ["Foo"]
},
{
Expand Down
18 changes: 9 additions & 9 deletions src/__fixtures__/Events/08-implicit-close-tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{
"event": "text",
"startIndex": 56,
"endIndex": 58,
"endIndex": 57,
"data": ["TH"]
},
{
Expand Down Expand Up @@ -149,7 +149,7 @@
{
"event": "text",
"startIndex": 76,
"endIndex": 83,
"endIndex": 82,
"data": ["Heading"]
},
{
Expand Down Expand Up @@ -209,7 +209,7 @@
{
"event": "text",
"startIndex": 101,
"endIndex": 104,
"endIndex": 103,
"data": ["Div"]
},
{
Expand Down Expand Up @@ -251,7 +251,7 @@
{
"event": "text",
"startIndex": 119,
"endIndex": 123,
"endIndex": 122,
"data": ["Div2"]
},
{
Expand Down Expand Up @@ -329,7 +329,7 @@
{
"event": "text",
"startIndex": 156,
"endIndex": 165,
"endIndex": 164,
"data": ["Heading 2"]
},
{
Expand Down Expand Up @@ -371,7 +371,7 @@
{
"event": "text",
"startIndex": 189,
"endIndex": 193,
"endIndex": 192,
"data": ["Para"]
},
{
Expand All @@ -395,7 +395,7 @@
{
"event": "text",
"startIndex": 197,
"endIndex": 206,
"endIndex": 205,
"data": ["Heading 4"]
},
{
Expand Down Expand Up @@ -449,7 +449,7 @@
{
"event": "text",
"startIndex": 222,
"endIndex": 224,
"endIndex": 223,
"data": ["Hi"]
},
{
Expand All @@ -473,7 +473,7 @@
{
"event": "text",
"startIndex": 228,
"endIndex": 231,
"endIndex": 230,
"data": ["bye"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/09-attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{
"event": "text",
"startIndex": 56,
"endIndex": 60,
"endIndex": 59,
"data": ["adsf"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/10-crazy-attrib.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{
"event": "text",
"startIndex": 15,
"endIndex": 20,
"endIndex": 19,
"data": ["stuff"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/11-script_in_script.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
"event": "text",
"startIndex": 11,
"endIndex": 44,
"endIndex": 43,
"data": ["var str = '<script></'+'script>';"]
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/__fixtures__/Events/14-implicit-open-tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 5,
"endIndex": 10,
"endIndex": 9,
"data": ["Hallo"]
},
{
Expand All @@ -41,7 +41,7 @@
{
"event": "text",
"startIndex": 14,
"endIndex": 19,
"endIndex": 18,
"data": ["World"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/15-lt-whitespace.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 5,
"endIndex": 4,
"data": ["a < b"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/17-numeric_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 36,
"endIndex": 35,
"data": ["abcdfg&#x;h"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/18-legacy_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 32,
"endIndex": 31,
"data": ["&elíe&eer;s<er&sum"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/19-named_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 53,
"endIndex": 52,
"data": ["&el<er∳foo&bar"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/20-xml_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 49,
"endIndex": 48,
"data": ["&>&amp<&uuml;a&#x62c&#100&#101"]
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/__fixtures__/Events/22-double_brackets.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 1,
"endIndex": 0,
"data": ["<"]
},
{
Expand All @@ -23,7 +23,7 @@
{
"event": "text",
"startIndex": 19,
"endIndex": 27,
"endIndex": 26,
"data": [">testing"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/23-legacy_entity_fail.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 3,
"endIndex": 2,
"data": ["M&M"]
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/__fixtures__/Events/24-special_special.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 7,
"endIndex": 24,
"endIndex": 23,
"data": ["<b>foo</b><title>"]
},
{
Expand Down Expand Up @@ -113,7 +113,7 @@
{
"event": "text",
"startIndex": 84,
"endIndex": 99,
"endIndex": 98,
"data": ["</scripter</soo"]
},
{
Expand All @@ -137,7 +137,7 @@
{
"event": "text",
"startIndex": 115,
"endIndex": 123,
"endIndex": 122,
"data": ["</styler"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/25-empty_tag_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 7,
"endIndex": 6,
"data": ["< ></ >"]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 8,
"endIndex": 9,
"endIndex": 8,
"data": ["<"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/34-not-alpha-tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 8,
"endIndex": 7,
"data": ["<12>text"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/36-entity-in-attrib.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{
"event": "text",
"startIndex": 44,
"endIndex": 75,
"endIndex": 74,
"data": ["?&image_uri=1&ℑ=2&image=3"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/37-entity-in-title.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 7,
"endIndex": 27,
"endIndex": 26,
"data": ["the \"title\""]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/38-entity-in-title-no-decode.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"event": "text",
"startIndex": 7,
"endIndex": 28,
"endIndex": 27,
"data": ["the &quot;title&quot;"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/39-title-in-script.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"event": "text",
"startIndex": 8,
"endIndex": 18,
"endIndex": 17,
"data": ["'</title>'"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/41-trailing-legacy-entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 19,
"endIndex": 18,
"data": ["⨱×bar"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/42-trailing-numeric-entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 8,
"endIndex": 7,
"data": ["55"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/__fixtures__/Events/43-multibyte-entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"event": "text",
"startIndex": 0,
"endIndex": 21,
"endIndex": 20,
"data": ["≧̸"]
}
]
Expand Down
Loading