Skip to content

Commit

Permalink
Item12337: remove dependency on version 4.0 of HTML::TreeBuilder
Browse files Browse the repository at this point in the history
Okay, here's the story again. HTML::TreeBuilder does a lot of entity mangling
by default. HTML::Entities assumes ISO-8859-1 when working on byte strings.
Therefore, things tend to break if the charset isn't ISO-8859-1.

The original fix for Item11755 was to stop entity processing completely, but
that requires a new feature in HTML::TreeBuilder 4.0.

Before that, I tried fixing the problem by throwing Encode calls into the code
various ways, but didn't manage to hit just the right combination. It turns
out that if you convert the initial input into a Unicode string and the final
output back into a byte string, things work as desired. So, do that.


git-svn-id: http://svn.foswiki.org/trunk@16354 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
JanKrueger authored and JanKrueger committed Jan 9, 2013
1 parent 4f41db2 commit bb0751c
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use warnings;
use Foswiki::UI ();
use Foswiki::Func ();
use Foswiki::Plugins ();
use Encode;
use Encode ();

use HTML::TreeBuilder ();
use Algorithm::Diff ();
Expand Down Expand Up @@ -292,6 +292,9 @@ sub compare {

$output .= $tmpl_after;

# Item12337: part of alternative fix for Item11755
$output = Encode::encode( $Foswiki::cfg{Site}{CharSet}, $output );

# Break circular references to avoid memory leaks. (Tasks:9127)
$tree1 = $tree1->parent() while defined $tree1->parent();
$tree1->delete();
Expand Down Expand Up @@ -324,11 +327,13 @@ sub _getTree {
$text =~ s/^\s*//;
$text =~ s/\s*$//;

# Item12337: part of alternative fix for Item11755
$text = Encode::decode( $Foswiki::cfg{Site}{CharSet}, $text );

# Generate tree

my $tree = new HTML::TreeBuilder;
$tree->implicit_body_p_tag(1);
$tree->no_expand_entities(1); # Item11755
$tree->p_strict(1);
$tree->parse($text);
$tree->eof;
Expand Down

0 comments on commit bb0751c

Please sign in to comment.