From f6705f06c0a8251c0f3eb0fe88532e75645f7705 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Mon, 9 Feb 2009 17:29:27 -0500 Subject: Fixed #1170: Auto-linking bug when URL cotains special chars. --- lib/util.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 7ce4e229e..5204693bc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -412,8 +412,8 @@ function common_replace_urls_callback($text, $callback) { // Then clean up what the regex left behind $offset = 0; - foreach($matches[0] as $url) { - $url = htmlspecialchars_decode($url); + foreach($matches[0] as $orig_url) { + $url = htmlspecialchars_decode($orig_url); // Make sure we didn't pick up an email address if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue; @@ -456,6 +456,9 @@ function common_replace_urls_callback($text, $callback) { if (!in_array($url_parts[2], $tlds)) continue; + // Put the url back the way we found it. + $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url); + // Call user specified func $modified_url = $callback($url); -- cgit v1.2.3-54-g00ecf From cf29ef2bc484c1d9719e852d1d3b6eeaff74e094 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Mon, 9 Feb 2009 19:15:30 -0500 Subject: Fixed remaining substr_replace with multibyte equivalent. --- lib/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index be92f422f..75d1e21a4 100644 --- a/lib/util.php +++ b/lib/util.php @@ -446,7 +446,7 @@ function common_replace_urls_callback($text, $callback) { // If the first part wasn't cap'd but the last part was, we captured too much if ((!$prev_part && $last_part)) { - $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0)); + $url = mb_substr($url, 0 , mb_strpos($url, '.'.$url_parts['2'], 0)); } // Capture the new TLD -- cgit v1.2.3-54-g00ecf From 646fdea1bf8a93bbfb60212982a218994ffa8bbe Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Tue, 10 Feb 2009 17:42:58 -0500 Subject: Fixed 1174: schemeless URL auto-linking bug --- lib/util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/util.php b/lib/util.php index 75d1e21a4..a130c7d49 100644 --- a/lib/util.php +++ b/lib/util.php @@ -418,8 +418,8 @@ function common_replace_urls_callback($text, $callback) { // Make sure we didn't pick up an email address if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue; - // Remove trailing punctuation - $url = rtrim($url, '.?!,;:\'"`'); + // Remove surrounding punctuation + $url = trim($url, '.?!,;:\'"`([<'); // Remove surrounding parens and the like preg_match('/[)\]>]+$/', $url, $trailing); -- cgit v1.2.3-54-g00ecf