From e66092deaafdb3bfded9d3f8de8453b9d4e75e1e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 2 Nov 2010 11:28:20 -0700 Subject: [PATCH] Anchor words to replace in processReplacements. Fixes bug #11939. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/HTML.pm | 20 +++++++++----------- t/HTML.t | 5 +++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index e66378190..2492c5a7c 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -23,6 +23,7 @@ - fixed #11933: EMS shows a dollar currency symbol on Badge Listing - fixed #11941: cannot edit default templates in some browsers - fixed #11926: Version Tag: Delete + - fixed #11939: WebGUI replacements are not anchored. 7.10.3 - fixed #11903: Unnecessary debug in Thingy diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm index 2e9c80f1d..299ffa7ea 100644 --- a/lib/WebGUI/HTML.pm +++ b/lib/WebGUI/HTML.pm @@ -387,20 +387,18 @@ sub processReplacements { my $session = shift; my ($content) = @_; my $replacements = $session->stow->get("replacements"); - if (defined $replacements) { - foreach my $searchFor (keys %{$replacements}) { - my $replaceWith = $replacements->{$searchFor}; - $content =~ s/\Q$searchFor/$replaceWith/gs; - } - } else { + if (! defined $replacements) { my $sth = $session->dbSlave->read("select searchFor,replaceWith from replacements"); - while (my ($searchFor,$replaceWith) = $sth->array) { + while (my ($searchFor,$replaceWith) = $sth->array) { $replacements->{$searchFor} = $replaceWith; - $content =~ s/\Q$searchFor/$replaceWith/gs; - } - $sth->finish; - $session->stow->set("replacements",$replacements); + } + $sth->finish; + $session->stow->set("replacements",$replacements); } + foreach my $searchFor (keys %{$replacements}) { + my $replaceWith = $replacements->{$searchFor}; + $content =~ s/\b\Q$searchFor\E\b/$replaceWith/gs; + } return $content; } diff --git a/t/HTML.t b/t/HTML.t index 66800b9ba..41500943c 100644 --- a/t/HTML.t +++ b/t/HTML.t @@ -129,6 +129,7 @@ my @htmlTextSets = ( my $numTests = scalar @filterSets + scalar @macroParamSets + scalar @htmlTextSets + + 3 ; plan tests => $numTests; @@ -147,3 +148,7 @@ foreach my $testSet (@htmlTextSets) { my $text = WebGUI::HTML::html2text($testSet->{inputText}); is($text, $testSet->{output}, $testSet->{comment}); } + +is(WebGUI::HTML::processReplacements($session, 'grass'), 'grass', 'processReplacements: grass is not replaced'); +is(WebGUI::HTML::processReplacements($session, 'shitake'), 'shitake', '... shitake is not replaced'); +is(WebGUI::HTML::processReplacements($session, 'This is shit.'), 'This is crap.', '... shit is replaced');