]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #5706. Allowing parens in URIs if not last character.
authorBrett Profitt <brett.profitt@gmail.com>
Tue, 9 Jul 2013 16:13:17 +0000 (12:13 -0400)
committerBrett Profitt <brett.profitt@gmail.com>
Tue, 9 Jul 2013 16:13:17 +0000 (12:13 -0400)
engine/lib/output.php
engine/tests/regression/trac_bugs.php

index 5adc01053dde19f9f3bdc06d6904121cc8e7fb57..6172a5c8d6c1d7387280bfc41ca79f3ce7229c72 100644 (file)
@@ -27,16 +27,16 @@ function parse_urls($text) {
        // By default htmlawed rewrites tags to this format.
        // if PHP supported conditional negative lookbehinds we could use this:
        // $r = preg_replace_callback('/(?<!=)(?<![ ])?(?<!["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\),]+)/i',
-       $r = preg_replace_callback('/(?<![=\/"\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\(\)]+)/i',
+       $r = preg_replace_callback('/(?<![=\/"\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\']+)/i',
        create_function(
                '$matches',
                '
                        $url = $matches[1];
-                       $punc = \'\';
+                       $punc = "";
                        $last = substr($url, -1, 1);
-                       if (in_array($last, array(".", "!", ","))) {
+                       if (in_array($last, array(".", "!", ",", "(", ")"))) {
                                $punc = $last;
-                               $url = rtrim($url, ".!,");
+                               $url = rtrim($url, ".!,()");
                        }
                        $urltext = str_replace("/", "/<wbr />", $url);
                        return "<a href=\"$url\" rel=\"nofollow\">$urltext</a>$punc";
index 5730830bb09b437b7545904e645d50deec7b452e..f173b5b9fd3942de232659a0e4a28eac5a80b8b2 100644 (file)
@@ -291,6 +291,9 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
 
                        'unquoted already anchor <a href=http://www.yahoo.com>yahoo</a>' =>
                                'unquoted already anchor <a href=http://www.yahoo.com>yahoo</a>',
+
+                       'parens in uri http://thedailywtf.com/Articles/A-(Long-Overdue)-BuildMaster-Introduction.aspx' =>
+                               'parens in uri <a href="http://thedailywtf.com/Articles/A-(Long-Overdue)-BuildMaster-Introduction.aspx" rel="nofollow">http:/<wbr />/<wbr />thedailywtf.com/<wbr />Articles/<wbr />A-(Long-Overdue)-BuildMaster-Introduction.aspx</a>'
                );
                foreach ($cases as $input => $output) {
                        $this->assertEqual($output, parse_urls($input));