Skip to content
Permalink
Browse files

Item12407: Call no_expand_entities if possible

The real fix for Compare entity encoding issues is to use a modern
version of HTML::TreeBuilder and set the no_expand_entites flag.
Otherwise, when the topic is imported, all entities are decoded,
"activating" encoded tags.

git-svn-id: http://svn.foswiki.org/trunk@17633 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
GeorgeClark GeorgeClark
GeorgeClark authored and GeorgeClark committed May 4, 2014
1 parent 008189b commit 0dffab4d3cc54eaed58c295452d4a4f7fd7a4c21
Showing with 8 additions and 3 deletions.
  1. +8 −3 CompareRevisionsAddOn/lib/Foswiki/Contrib/CompareRevisionsAddOn/Compare.pm
@@ -28,6 +28,7 @@ my $class_c1 = 'craCompareChange1';
my $class_c2 = 'craCompareChange2';
my $interweave;
my $scripturl;
my $v40plus = HTML::TreeBuilder->can('no_expand_entities');

sub compare {
my $session = shift;
@@ -351,8 +352,9 @@ sub _getTree {
$tree->implicit_body_p_tag(1);
$tree->p_strict(1);

# SMELL: This option is only valid on HTML:Treebuilder >= 4.0. See Item12337 and Item12407
# $tree->no_expand_entities(1);
# SMELL: This next option is only valid on HTML:Treebuilder >= 4.0. See Item12337 and Item12407
# On older versions of TreeBuilder, escaped html like <pre> will be un-escaped
$tree->no_expand_entities(1) if $v40plus;
$tree->parse($text);
$tree->eof;
$tree->elementify;
@@ -547,7 +549,10 @@ sub _getTextWithClass {

# Item11755: prevent entity mangling
# SMELL: Alternative to $tree->no_expand_entities(1); See Item12337 and Item12407
return $element->as_HTML( '<>&', undef, {} );
# This fix is not 100%, but helps in some cases. The real solution is to install
# latest HTML::Tree.
my $entities = ($v40plus) ? '' : '<>&';
return $element->as_HTML( $entities, undef, {} );
}
elsif ($class) {
return '<span class="' . $class . '">' . $element . '</span>';

0 comments on commit 0dffab4

Please sign in to comment.
You can’t perform that action at this time.