diff --git a/crates/obscura-dom/src/serialize.rs b/crates/obscura-dom/src/serialize.rs index 7a489a5..608b5b4 100644 --- a/crates/obscura-dom/src/serialize.rs +++ b/crates/obscura-dom/src/serialize.rs @@ -72,7 +72,17 @@ impl DomTree { } NodeData::Comment { contents } => { buf.push_str("" (that ends the comment), but script can via + // document.createComment("a-->b"). Emitting it verbatim would close + // the comment early and let the trailing text escape into markup. + // Neutralize the terminator so the serialized output round-trips as + // a single comment. + if contents.contains("-->") { + buf.push_str(&contents.replace("-->", "-->")); + } else { + buf.push_str(contents); + } buf.push_str("-->"); } NodeData::ProcessingInstruction { target, data } => {