[Rt-commit] rt branch, 4.0/clicky-match-decoded-html, created. rt-4.0.9-15-g4f50559

? sunnavy sunnavy at bestpractical.com
Thu Jan 24 11:31:14 EST 2013


The branch, 4.0/clicky-match-decoded-html has been created
        at  4f50559774610f548fc79f1496d69d8ae4b4b6ed (commit)

- Log -----------------------------------------------------------------
commit 67e8f4a2e49ef52ae123cace47dc174f59580770
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jan 25 00:07:01 2013 +0800

    re-matching decoded link html to avoid following things like "
    
    e.g. http://example.com/" should be parsed without the ending quote(")
         http://example.com/& is valid though

diff --git a/share/html/Elements/MakeClicky b/share/html/Elements/MakeClicky
index e989edc..f384f5d 100644
--- a/share/html/Elements/MakeClicky
+++ b/share/html/Elements/MakeClicky
@@ -47,6 +47,7 @@
 %# END BPS TAGGED BLOCK }}}
 <%ONCE>
 use Regexp::Common qw(URI);
+use HTML::Entities qw(decode_entities encode_entities);
 
 my %actions = (
     default => sub {
@@ -140,6 +141,16 @@ while ( $$content =~ /($regexp)/gsio ) {
     my $match = $1;
     next if $` =~ /href=(?:"|")$/;
     my $skipped_len = pos($$content) - $pos - length($match);
+
+    if ( $html ) {
+        # re-match the decoded string to avoid things like the quote in
+        # http://example.com/?foo"
+
+        if ( decode_entities($match) =~ /($regexp)/sio ) {
+            $match = encode_entities($1);
+        }
+    }
+
     if ( $skipped_len > 0 ) {
         my $plain;
         if ( $html ) {

commit 4f50559774610f548fc79f1496d69d8ae4b4b6ed
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jan 25 00:11:04 2013 +0800

    clicky tests for edge cased links in html

diff --git a/t/ticket/clicky.t b/t/ticket/clicky.t
index 20d39a3..368d63c 100644
--- a/t/ticket/clicky.t
+++ b/t/ticket/clicky.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use Test::More;
-use RT::Test tests => 20;
+use RT::Test tests => undef;
 
 my $plain = MIME::Entity->build(
     Subject => 'plain mime',
@@ -29,6 +29,10 @@ or find known bugs on http://rt3.fsck.com
 
 to test anchor:
 https://wiki.bestpractical.com/test#anchor
+
+to test html codes
+https://wiki.bestpractical.com/test/html/quote"
+https://wiki.bestpractical.com/test/html/valid&
 --
 Best regards. BestPractical Team.
 END
@@ -114,6 +118,20 @@ diag 'test httpurl';
         text => 'Open URL',
     );
     ok( scalar @links, 'found clicky link with anchor' );
+
+    @links = $m->find_link(
+        tag  => 'a',
+        url  => 'https://wiki.bestpractical.com/test/html/quote',
+        text => 'Open URL',
+    );
+    ok( scalar @links, 'found clicky link without "' );
+
+    @links = $m->find_link(
+        tag  => 'a',
+        url  => 'https://wiki.bestpractical.com/test/html/valid&',
+        text => 'Open URL',
+    );
+    ok( scalar @links, 'found clicky link with &' );
 }
 
 diag 'test httpurl_overwrite';
@@ -139,3 +157,4 @@ diag 'test httpurl_overwrite';
     ok( scalar @links, 'found clicky link with anchor' );
 }
 
+done_testing;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list