Skip to content
Open
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
20 changes: 20 additions & 0 deletions src/rewritable_units/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,26 @@ mod tests {
);
}

#[test]
fn add_valueless_attr() {
test!(
|el| {
el.set_attribute("a5", "").unwrap();
},
r#"<a a1='foo " baré " baz' a2="foo ' bar ' baz" a3=foo/bar a4 a5></a>"#
);
}

#[test]
fn clear_value_to_valueless_attr() {
test!(
|el| {
el.set_attribute("a2", "").unwrap();
},
r#"<a a1='foo " baré " baz' a2 a3=foo/bar a4></a>"#
);
}

#[test]
fn self_closing_flag() {
// NOTE: we should add space between valueless attr and self-closing slash
Expand Down
2 changes: 2 additions & 0 deletions src/rewritable_units/tokens/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl Serialize for &Attribute<'_> {
fn into_bytes(self, output_handler: &mut dyn FnMut(&[u8])) -> Result<(), RewritingError> {
if let Some(raw) = self.raw.as_ref() {
output_handler(raw);
} else if self.value.is_empty() {
output_handler(&self.name);
} else {
output_handler(&self.name);
output_handler(b"=\"");
Expand Down