Possible bug in HTML::Element::as_HTML (< and > in scripts)
Adam Janin (janin@cs.berkeley.edu)
Thu, 22 Jan 1998 16:59:24 -0800
When parsing scripts, it seems to me that as_HTML should not convert < to
<, etc.
The problem is expressions like:
if (a < b) {
get converted to
if (a < b)
which the interpreter fails on.
Below is a new version of Element::as_HTML.
sub as_HTML
{
my $self = shift;
my @html = ();
my $tag;
my $enc;
$self->traverse(
sub {
my($node, $start, $depth) = @_;
if (ref $node) {
$tag = $node->tag;
if ($start) {
if ($tag eq "script") {
$enc = 0;
}
push(@html, $node->starttag);
} else {
if ($tag eq "script") {
$enc = 1;
}
if (not ($emptyElement{$tag} or $optionalEndTag{$tag})) {
push(@html, $node->endtag);
}
}
} else {
# simple text content
if ($enc) {
HTML::Entities::encode_entities($node, "<>&");
}
push(@html, $node);
}
}
);
# join('', @html, "\n"); -- AJ (Just for ease of reading)
join("\n", @html, "\n");
}