{"record":{"id":"94ce0ccd9e455921","repo":"swc-project/swc","slug":"noelementtoclosebutendtagseen","errorCode":"NoElementToCloseButEndTagSeen","errorMessage":"No \"{tag_name}\" element in scope but a \"{tag_name}\" end tag seen","messagePattern":"No \"(.+?)\" element in scope but a \"(.+?)\" end tag seen","errorType":"validation","errorClass":"swc_html_parser::error::Error","httpStatus":null,"severity":"warning","filePath":"crates/swc_html_parser/src/parser/mod.rs","lineNumber":7314,"sourceCode":"                });\n\n            if formatting_element.is_none() {\n                self.any_other_end_tag_for_in_body_insertion_mode(token_and_info);\n\n                return Ok(());\n            }\n\n            let formatting_element = formatting_element.unwrap();\n\n            // 4.\n            let formatting_element_stack_index = self\n                .open_elements_stack\n                .items\n                .iter()\n                .rposition(|n| is_same_node(n, &formatting_element.1));\n\n            if formatting_element_stack_index.is_none() {\n                self.errors.push(Error::new(\n                    token_and_info.span,\n                    ErrorKind::NoElementToCloseButEndTagSeen(subject),\n                ));\n                self.active_formatting_elements\n                    .remove(&formatting_element.1);\n\n                return Ok(());\n            }\n\n            // 5.\n            if formatting_element_stack_index.is_some()\n                && !self\n                    .open_elements_stack\n                    .has_node_in_scope(&formatting_element.1)\n            {\n                self.errors.push(Error::new(\n                    token_and_info.span,\n                    ErrorKind::NoElementToCloseButEndTagSeen(subject),","sourceCodeStart":7296,"sourceCodeEnd":7332,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_html_parser/src/parser/mod.rs#L7296-L7332","documentation":"Inside the adoption agency algorithm (used for formatting end tags like `</b>`, `</a>`, `</em>`), step 4 locates the formatting element from the list of active formatting elements on the stack of open elements. If it is not on the stack at all (crates/swc_html_parser/src/parser/mod.rs:7314), the parser reports `NoElementToCloseButEndTagSeen`, removes the element from the active formatting list, and ignores the token.","triggerScenarios":"A formatting element still referenced by the active formatting elements list but no longer present on the open elements stack — typically after table/text insertion-mode handling popped it — followed by its end tag. Example shape: `<b><li>x</b>` variants where earlier recovery left the lists inconsistent, then `</b>` arrives.","commonSituations":"Deeply mis-nested formatting tags produced by WYSIWYG editors; malformed HTML round-tripped through tolerant tools; inputs intentionally crafted to stress the adoption agency (fuzz corpora, legacy CMS output).","solutions":["Fix the source so formatting elements are closed in LIFO order where practical","Re-serialize the document through a tolerant parser (parse then print) to normalize the lists","If untrusted input, cap nesting/formatting depth before parsing","Treat as recoverable: the parser drops the token and continues; verify the final tree"],"exampleFix":"<!-- before (mis-nested formatting) -->\n<b><i>one</b>two</i>\n<!-- after -->\n<b><i>one</i></b><i>two</i>","handlingStrategy":"validation","validationCode":"// Normalize before parsing: run the tolerant parser once and re-serialize\nlet normalized = {\n    let mut parser = Parser::new(lexer);\n    let doc = parser.parse_document()?;\n    print_document(&doc)? // re-serialization resets active-formatting state\n};","typeGuard":null,"tryCatchPattern":"for err in parser.take_errors() {\n    if matches!(err.kind, ErrorKind::NoElementToCloseButEndTagSeen(_)) {\n        // end tag ignored; formatting entry removed from active list\n    }\n}","preventionTips":["Close formatting tags in LIFO order in generated markup","Round-trip untrusted/mangled HTML through parse+print before deep processing","Cap formatting-tag nesting depth in sanitizers to avoid pathological adoption-agency inputs"],"tags":["html","adoption-agency","formatting-elements","mis-nesting","parse-error"],"backgroundTag":"html5-parse-error","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}