Skip to content

Commit 51528c4

Browse files
committed
Fix: #227
Test for #227 was broken by previous commit. This fixes it. All tests are now passing.
1 parent a81fc46 commit 51528c4

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/nodes/html.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,12 +1200,20 @@ export function base_parse(data: string, options = {} as Partial<Options>) {
12001200
'';
12011201
if (kElementsClosedByClosingExcept[openTag]) {
12021202
const closingTag = tagName.toLowerCase();
1203-
if (!kElementsClosedByClosingExcept[openTag][closingTag]) {
1204-
// Update range end for closed tag
1205-
(<[number, number]>currentParent.range)[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1206-
stack.pop();
1207-
currentParent = arr_back(stack);
1208-
continue;
1203+
if (stack.length > 1) {
1204+
const possibleContainer = stack[stack.length - 2];
1205+
if (
1206+
possibleContainer &&
1207+
possibleContainer.rawTagName &&
1208+
possibleContainer.rawTagName.toLowerCase() === closingTag &&
1209+
!kElementsClosedByClosingExcept[openTag][closingTag]
1210+
) {
1211+
// Update range end for closed tag
1212+
(<[number, number]>currentParent.range)[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1213+
stack.pop();
1214+
currentParent = arr_back(stack);
1215+
continue;
1216+
}
12091217
}
12101218
}
12111219
// Use aggressive strategy to handle unmatching markups.

0 commit comments

Comments
 (0)