From 334d496bb1779d9b9d06d8427da50e751bd2a98d Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Fri, 16 Jan 2015 19:10:34 +0100 Subject: Fix some issues with tagging. --- include/text.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/include/text.php b/include/text.php index c130a9b8a..b6e4abf24 100644 --- a/include/text.php +++ b/include/text.php @@ -606,9 +606,11 @@ function get_tags($s) { $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s); // ignore anything in [style= ] - $s = preg_replace('/\[style=(.*?)\]/sm','',$s); + // ignore anything in [color= ], because it may contain color codes which are mistaken for tags + $s = preg_replace('/\[color=(.*?)\]/sm','',$s); + // match any double quoted tags if(preg_match_all('/([@#]\"\;.*?\"\;)/',$s,$match)) { @@ -620,12 +622,11 @@ function get_tags($s) { // Match full names against @tags including the space between first and last // We will look these up afterward to see if they are full names or not recognisable. - if(preg_match_all('/(@[^ \x0D\x0A,:?\[]+ [^ \x0D\x0A@,:?\[]+)([ \x0D\x0A@,:?\[]|$)/',$s,$match)) { + // The lookbehind is used to prevent a match in the middle of a word + // '=' needs to be avoided because when the replacement is made (in handle_tag()) it has to be ignored there + // Feel free to allow '=' if the issue with '=' is solved in handle_tag() + if(preg_match_all('/(?get_baseurl() . '/search?tag=' . rawurlencode($basetag); $newtag = '#[zrl=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/zrl]'; - //replace tag by the link - $body = str_replace($tag, $newtag, $body); + //replace tag by the link. Make sure to not replace something in the middle of a word + // The '=' is needed to not replace color codes if the code is also used as a tag + // Much better would be to somehow completely avoiding things in e.g. [color]-tags. + // This would allow writing things like "my favourite tag=#foobar". + $body = preg_replace('/(?