Skip to content

Commit

Permalink
Item8592: Fix to generate anchors that include < and > that are not p…
Browse files Browse the repository at this point in the history
…art of an HTML tag. With this fix,

the unit tests pass, and PerlDoc?module=Foswiki::Func generates usable links in the TOC.



git-svn-id: http://svn.foswiki.org/trunk@7285 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Apr 28, 2010
1 parent 905ff7a commit f95fa32
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions UnitTestContrib/test/unit/TOCTests.pm
Expand Up @@ -214,6 +214,7 @@ sub test_TOC_makeAnchorName {
['TEST_33_WikiWord', 'TEST ! WikiWord', 'WikiWord and !'], # Unescaped WikiWord
['TEST_WikiWord', 'TEST <nop>WikiWord', '<nop> Escaped WikiWord'], # Escaped WikiWord
['TEST_WikiWord', 'TEST !WikiWord', '! Escaped WikiWord'], # Escaped WikiWord
['TEST_asdf', 'TEST <a href="A1"> asdf', 'valid tag'],
['TEST_60_62', 'TEST <>', 'Null tag'], # Less / greater than.
['TEST_62', 'TEST >', 'Greater-than'], # Greater-than
['TEST_60', 'TEST <', 'Less-than'], # Less-than
Expand Down
9 changes: 9 additions & 0 deletions core/lib/Foswiki/Render.pm
Expand Up @@ -419,6 +419,7 @@ sub _makeAnchorTarget {
{ name => $this->_makeAnchorNameUnique( $topicObject, $goodAnchor ), },
''
);
#print STDERR "INITIAL = $text ... GOODANCHOR = $goodAnchor ... HTML = $html\n";

if ( $Foswiki::cfg{RequireCompatibleAnchors} ) {

Expand Down Expand Up @@ -464,6 +465,14 @@ sub _makeAnchorName {
$text =~ s/[^\x00-\xFF]//g;
ASSERT( $text !~ /[^\x00-\xFF]/ ) if DEBUG;

# SMELL: This corrects for anchors containing < and >
# which for some reason are encoded when building the anchor, but
# un-encoded when building the link.
#
# Convert < and > back from entity
$text =~ s/&lt;/</g;
$text =~ s/&gt;/>/g;

# remove HTML tags and entities
$text =~ s/<\/?[a-zA-Z][^>]*>//gi;
$text =~ s/&#?[a-zA-Z0-9]+;//g;
Expand Down

0 comments on commit f95fa32

Please sign in to comment.