aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-30 22:42:13 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-30 22:42:13 +0000
commit0068d7f46452188f807e413f6cbd32cd765e6530 (patch)
tree5fcacc7beeaa5f3ba52545bca8124807954e1da5 /engine/lib
parent7b9ec5afdab5d3e873da3e2b18cc5060a1f46585 (diff)
downloadelgg-0068d7f46452188f807e413f6cbd32cd765e6530.tar.gz
elgg-0068d7f46452188f807e413f6cbd32cd765e6530.tar.bz2
Refs #1425: Cleaned up regexp for parlse_urls().
git-svn-id: http://code.elgg.org/elgg/trunk@3861 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/input.php18
1 files changed, 16 insertions, 2 deletions
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 27204682f..019e4faa0 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -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;
}
/**