Skip to content

Commit

Permalink
improve support for empty attributes in Mojo::DOM::HTML (closes #846)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 24, 2015
1 parent 7a65c82 commit 56af831
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

6.22 2015-09-24
6.22 2015-09-25
- Improved Mojo::JSON by reusing JSON::PP boolean constants.
- Improved support for empty attributes in Mojo::DOM::HTML.

6.21 2015-09-23
- Added val method to Mojo::DOM.
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -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 .= $xml ? qq{ $key="$key"} : " $key" and next unless defined $value;
$result .= qq{ $key="} . xml_escape($value) . '"';
}

# No children
Expand Down
3 changes: 2 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -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,
Expand Down

0 comments on commit 56af831

Please sign in to comment.