From b76169a214626c3dc7d90b68e5033d751604affc Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Tue, 25 Apr 2006 22:47:42 +0000 Subject: [PATCH] filterlib/filter_phrases() - try to escape magic characters used internally by the filter mechanism -- Bug#5236 / WR#422 This is an attempt to fix filter problems caused by glossary matches on % (which also affect matches on * and #). Works for the sample cases I have, but we may be breaking subtly in other places. --- lib/filterlib.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/filterlib.php b/lib/filterlib.php index fcf037a26b..00972bff20 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -82,6 +82,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc foreach ($ignoretagsclose as $close) $filterignoretagsclose[] = $close; } + //// Double up some magic chars to avoid "accidental matches" + $text = preg_replace('/([#*%])/','\1\1',$text); + ////Remove everything enclosed by the ignore tags from $text filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags); @@ -115,6 +118,11 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc $linkobject->work_hreftagbegin = $linkobject->hreftagbegin; $linkobject->work_hreftagend = $linkobject->hreftagend; } + + /// Double up chars to protect true duplicates + /// be cleared up before returning to the user. + $linkobject->work_hreftagbegin = preg_replace('/([#*%])/','\1\1',$linkobject->work_hreftagbegin); + if (empty($linkobject->casesensitive)) { $linkobject->work_casesensitive = false; } else { @@ -129,6 +137,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc /// Strip tags out of the phrase $linkobject->work_phrase = strip_tags($linkobject->phrase); + /// Double up chars that might cause a false match -- the duplicates will + /// be cleared up before returning to the user. + $linkobject->work_phrase = preg_replace('/([#*%])/','\1\1',$linkobject->work_phrase); /// Set the replacement phrase properly if ($linkobject->replacementphrase) { //We have specified a replacement phrase @@ -220,6 +231,9 @@ function filter_phrases ($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsc $text = str_replace(array_keys($ignoretags),$ignoretags,$text); } + //// Remove the protective doubleups + $text = preg_replace('/([#*%])(\1)/','\1',$text); + /// Add missing javascript for popus $text = filter_add_javascript($text); -- 2.39.5