From 8cd474e985fcce754f435b8b8fa84c33a9d623e7 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 16:06:04 -0400 Subject: Correct the hash tag test --- tests/HashTagDetectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/HashTagDetectionTest.php b/tests/HashTagDetectionTest.php index 71137b0b5..55e1f65bf 100644 --- a/tests/HashTagDetectionTest.php +++ b/tests/HashTagDetectionTest.php @@ -28,7 +28,7 @@ class HashTagDetectionTest extends PHPUnit_Framework_TestCase array('hello', 'hello'), array('#hello', - 'hello'), + '#'), ); } } -- cgit v1.2.3-54-g00ecf From 31329c33aee7f3d4b5c1dd80f32fcd45e7877850 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 25 Aug 2009 16:41:44 -0400 Subject: Handle grouping symbols ()[]{} correctly. Now passing all tests! --- lib/util.php | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/util.php b/lib/util.php index d4e2841cd..29eb6cbbc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -445,7 +445,7 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { '(?:/[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;]*)?'. // /path '(?:\?[\pN\pL\$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/]*)?'. // ?query string '(?:\#[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/\?\#]*)?'. // #fragment - ')(?'(', + 'right'=>')' + ), + array( + 'left'=>'[', + 'right'=>']' + ), + array( + 'left'=>'{', + 'right'=>'}' + ) + ); + $cannotEndWith=array('.','?',',','#'); + $original_url=$url; + do{ + $original_url=$url; + foreach($groupSymbolSets as $groupSymbolSet){ + if(substr($url,-1)==$groupSymbolSet['right']){ + $group_left_count = substr_count($url,$groupSymbolSet['left']); + $group_right_count = substr_count($url,$groupSymbolSet['right']); + if($group_left_count<$group_right_count){ + $right-=1; + $url=substr($url,0,-1); + } + } + } + if(in_array(substr($url,-1),$cannotEndWith)){ + $right-=1; + $url=substr($url,0,-1); + } + }while($original_url!=$url); + + if(empty($notice_id)){ - $result = call_user_func_array($callback,$matches['url']); + $result = call_user_func_array($callback,$url); }else{ - $result = call_user_func_array($callback, array($matches['url'],$notice_id) ); + $result = call_user_func_array($callback, array($url,$notice_id) ); } - return $left . $result . $right; + return substr($matches[0],0,$left) . $result . substr($matches[0],$right); } function curry($fn) { -- cgit v1.2.3-54-g00ecf