Anchor words to replace in processReplacements. Fixes bug #11939.

This commit is contained in:
Colin Kuskie 2010-11-02 11:28:20 -07:00
parent 59e848c6a8
commit e66092deaa
3 changed files with 15 additions and 11 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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');