-
-
Save anonymous/e45853c9baef8c3bb9a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/DOM/HTML.pm b/lib/Mojo/DOM/HTML.pm | |
index 016989a..48d3f8f 100644 | |
--- a/lib/Mojo/DOM/HTML.pm | |
+++ b/lib/Mojo/DOM/HTML.pm | |
@@ -228,8 +228,9 @@ sub _render { | |
# Attributes | |
for my $key (sort keys %{$tree->[2]}) { | |
- $result .= " $key" and next unless defined(my $value = $tree->[2]{$key}); | |
- $result .= " $key" . '="' . xml_escape($value) . '"'; | |
+ my $value = $tree->[2]{$key}; | |
+ $result .= " $key" and next if !defined $value && !$xml; | |
+ $result .= " $key" . '="' . xml_escape($value // $key) . '"'; | |
} | |
# No children | |
diff --git a/t/mojo/dom.t b/t/mojo/dom.t | |
index 14867c9..52d7e2f 100644 | |
--- a/t/mojo/dom.t | |
+++ b/t/mojo/dom.t | |
@@ -1918,7 +1918,8 @@ is $element->parent->tag, 'XMLTest', 'right parent'; | |
ok $element->root->xml, 'XML mode active'; | |
$dom->replace('<XMLTest2 /><XMLTest3 just="works" />'); | |
ok $dom->xml, 'XML mode active'; | |
-is $dom, '<XMLTest2 /><XMLTest3 just="works" />', 'right result'; | |
+$dom->at('XMLTest2')->{foo} = undef; | |
+is $dom, '<XMLTest2 foo="foo" /><XMLTest3 just="works" />', 'right result'; | |
# Ensure HTML semantics | |
ok !Mojo::DOM->new->xml(undef)->parse('<?xml version="1.0"?>')->xml, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment