Subject: | code error in HTML::Latex::parse_string |
Date: | Mon, 03 Mar 2008 01:53:53 -0800 |
To: | bug-HTML-Latex [...] rt.cpan.org |
From: | "kavi [...] netgables.com" <kavi [...] netgables.com> |
OS : Fedora Core 7
perl 5.8.8
HTML::Latex (latest from CPAN)
The following code needs fixing in Latex.pm (I fixed it, and it works
for me). Basically the $tree->parse($input) line should be followed by
$tree->eof (see comment below in code)
sub parse_string {
my ($conf,$input,$full) = @_;
return unless defined($input);
local $packages = $conf->{package} || [];
local $heads = $conf->{head} || [];
local $tags = $conf->{tag} || {};
local $options = $conf->{options} || {};
local $banned = $conf->{ban} || {};
local $pres = $conf->{pre} || {};
local $LOG = $conf->{log};
$options->{store} =~ s/^\s*~/$ENV{HOME}/ if exists $ENV{HOME};
print $LOG Dumper $conf if $options->{debug} > 1;
my $tree = HTML::TreeBuilder->new;
$tree->warn(1);
$tree->parse($input);
# need a call to eof, read perldoc HTML::TreeBuilder documentation
on the parse method for this
* $tree->eof;*
# end of fix
....
Repro steps :
Try to take a simple html file with a table in it (say), and try to
convert it to latex using the in-memory method of htm_string creation.
The following sample code and content will reproduce the bug.
content (pdftest.html)
------------------------------
<html>
<body>
<table>
<tr>
<td>
hello world
</td>
</tr>
</table>
</body>
</html>
sample code which will crash on above content
--------------------------------------------------------------
#! /usr/bin/perl
use HTML::Latex;
my $parser = new HTML::Latex;
open FILE, "< pdftest.html";
my $html_string = join("", <FILE>);
chomp $html_string;
my $tex_string = $parser->parse_string
print $tex_string
-----------------------------------------------------------------
Putting $tree->eof statement in HTML::Latex module in parse_string
method fixes the problem.