]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #1425: Cleaned up regexp for parlse_urls().
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 30 Jan 2010 22:42:13 +0000 (22:42 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 30 Jan 2010 22:42:13 +0000 (22:42 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3861 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/input.php

index 27204682fc9ec12bc6fb6529cde612ed642b9ef0..019e4faa081c77956965103058e6d87a7bc43fba 100644 (file)
@@ -111,15 +111,29 @@ function sanitise_filepath($path) {
  * @return string The output stirng with formatted links
  **/
 function parse_urls($text) {
-       return preg_replace_callback('/(?<!=["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\)]+)/i',
+       // @todo this causes problems with <attr = "val">
+       // must be ing <attr="val"> format (no space).
+       // 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',
+       //
+       // we can put , in the list of excluded char but need to keep . because of domain names.
+       // it is removed in the callback.
+       $r = preg_replace_callback('/(?<!=)(?<!["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\),]+)/i',
        create_function(
                '$matches',
                '
                        $url = $matches[1];
+                       if (substr($url, -1, 1) == \'.\') {
+                               $period = \'.\';
+                               $url = trim($url, \'.\');
+                       }
                        $urltext = str_replace("/", "/<wbr />", $url);
-                       return "<a href=\"$url\" style=\"text-decoration:underline;\">$urltext</a>";
+                       return "<a href=\"$url\" style=\"text-decoration:underline;\">$urltext</a>$period";
                '
        ), $text);
+
+       return $r;
 }
 
 /**