diff --git a/src/rewritable_units/element.rs b/src/rewritable_units/element.rs
index 784e5103..b3e13cf8 100644
--- a/src/rewritable_units/element.rs
+++ b/src/rewritable_units/element.rs
@@ -370,6 +370,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
fn prepend_chunk(&mut self, chunk: StringChunk) {
if self.can_have_content {
+ self.start_tag.set_self_closing_syntax(false);
self.start_tag
.mutations
.mutate()
@@ -434,6 +435,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
fn append_chunk(&mut self, chunk: StringChunk) {
if self.can_have_content {
+ self.start_tag.set_self_closing_syntax(false);
self.end_tag_mutations_mut().content_before.push_back(chunk);
}
}
@@ -492,6 +494,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
fn set_inner_content_chunk(&mut self, chunk: StringChunk) {
if self.can_have_content {
+ self.start_tag.set_self_closing_syntax(false);
self.remove_content();
self.start_tag
.mutations
diff --git a/src/rewritable_units/tokens/start_tag.rs b/src/rewritable_units/tokens/start_tag.rs
index 4542f303..a026f6eb 100644
--- a/src/rewritable_units/tokens/start_tag.rs
+++ b/src/rewritable_units/tokens/start_tag.rs
@@ -117,6 +117,10 @@ impl<'i> StartTag<'i> {
self.self_closing
}
+ pub(crate) fn set_self_closing_syntax(&mut self, has_slash: bool) {
+ self.self_closing = has_slash;
+ }
+
/// Inserts `content` before the start tag.
///
/// Consequent calls to the method append `content` to the previously inserted content.
diff --git a/src/rewriter/mod.rs b/src/rewriter/mod.rs
index 73511b61..ac336960 100644
--- a/src/rewriter/mod.rs
+++ b/src/rewriter/mod.rs
@@ -446,6 +446,30 @@ mod tests {
assert_eq!(res, "");
}
+ #[test]
+ fn rewrite_incorrect_self_closing() {
+ let res = rewrite_str::(
+ "
+