Skip Menu |
 

This queue is for tickets about the HTML-Tree CPAN distribution.

Report information
The Basics
Id: 15783
Status: resolved
Priority: 0/
Queue: HTML-Tree

People
Owner: Nobody in particular
Requestors: ian [...] indecorous.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.1901
Fixed in: (no value)



Subject: HTML::Element - self-closing tags like img don't self close
Download (untitled) / with headers
text/plain 298b
In HTML-Element-3.16, tags like "img" that are meant to close themselves in XHTML: <img src="foo.png" />. HTML::Element doesn't seem to be keen on XHTML, so it doesn't do it, but it's playing merry hell with me modifying a valid XHTML document and spitting it out again. I've attached a test case.
Download selfClose.t
text/x-perl 699b
use strict; BEGIN{ use vars qw( $tests ); use HTML::Element; $tests = scalar keys %{ HTML::Element->_empty_element_map }; } use Test::More tests => $tests + 1; for ( keys %HTML::Tagset::emptyElement ) { my $elem = HTML::Element->new( $_ ); my $expected = qq(<$_ />\n); if ( $_ eq "~pi" ) { $expected = "<?>\n"; } elsif ( $_ eq "~comment" ) { $expected = "<!---->\n"; } elsif ( $_ eq "~literal" ) { $expected = "\n"; } elsif ( $_ eq "~declaration" ) { $expected = "<!>\n"; } is ( $elem->as_HTML, $expected ); } my $elem = HTML::Element->new( 'span' ); my $expected = "<span></span>\n"; is ( $elem->as_HTML, $expected );
From: IMALPASS
Download (untitled) / with headers
text/plain 309b
The attached patch fixes the problem, although perhaps not in the ideal way. An option to turn on XHTML mode might be a good thing, although that should also turn on the quoting requested in http://rt.cpan.org/NoAuth/Bug.html?id=13744 (which actually requests the same change as this ticket as a postscript).
Download HTML-Element.patch
text/x-diff 444b
--- /usr/lib/perl5/site_perl/5.8.3/HTML/Element.pm 2003-09-15 04:03:08.000000000 -0500 +++ HTML/Element.pm 2005-11-11 14:45:58.000000000 -0600 @@ -1901,7 +1901,11 @@ $tag .= $html_uc ? qq{ \U$_\E=$val} : qq{ \L$_\E=$val}; } } - "$tag>"; + if ( scalar $self->content_list == 0 && $self->_empty_element_map->{ $self->tag } ) { + return $tag . " />"; + } else { + return $tag . ">"; + } }
Download (untitled) / with headers
text/plain 164b
[IMALPASS - Mon Nov 14 12:10:37 2005]: Show quoted text
> HTML::Element doesn't seem to be keen on XHTML
I realise, of course, that it's HTML::Element and not XHTML::Element....
I'm fixing this in whatever comes after 3.19_01. Thanks for the help.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.