Fix replacements (again). Add tests to test words and sequences with punctuation. Fixes bug #12208.
This commit is contained in:
parent
1cc7ac2578
commit
a3ff0fb7a5
3 changed files with 35 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
7.10.22
|
||||
- rfe #12207: Thingy. Field_name info returned by www_editThingDataSaveViaAjax
|
||||
- fixed #12206: Bad Subscription Groups in Duplicated Threads
|
||||
- fixed #12208: replacements don't work
|
||||
|
||||
7.10.21
|
||||
- added #9668 extension template variable to attachment loops for the following assets:
|
||||
|
|
|
|||
|
|
@ -397,7 +397,11 @@ sub processReplacements {
|
|||
}
|
||||
foreach my $searchFor (keys %{$replacements}) {
|
||||
my $replaceWith = $replacements->{$searchFor};
|
||||
$content =~ s/\b\Q$searchFor\E\b/$replaceWith/gs;
|
||||
my $pattern = qr/\Q$searchFor\E/;
|
||||
if ($searchFor =~ /^\w+/) {
|
||||
$pattern = qr/\b$pattern\b/;
|
||||
}
|
||||
$content =~ s/$pattern/$replaceWith/gs;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
|
|
|||
33
t/HTML.t
33
t/HTML.t
|
|
@ -65,7 +65,7 @@ my @filterSets = (
|
|||
},
|
||||
{
|
||||
inputText => q!<p>Paragraph</p>^H();!,
|
||||
output => q!Paragraph ^H();!,
|
||||
output => q|Paragraph ^H();|,
|
||||
type => 'all',
|
||||
comment => 'all filters macros and HTML',
|
||||
},
|
||||
|
|
@ -83,12 +83,12 @@ my @filterSets = (
|
|||
},
|
||||
{
|
||||
inputText => q! !,
|
||||
output => q!&nbsp;!,
|
||||
output => q|&nbsp;|,
|
||||
type => 'xml',
|
||||
comment => 'xml, ',
|
||||
},
|
||||
{
|
||||
inputText => q!> < "!,
|
||||
inputText => q|> < "|,
|
||||
output => q!> < "!,
|
||||
type => 'xml',
|
||||
comment => 'xml, other characters',
|
||||
|
|
@ -129,7 +129,7 @@ my @htmlTextSets = (
|
|||
my $numTests = scalar @filterSets
|
||||
+ scalar @macroParamSets
|
||||
+ scalar @htmlTextSets
|
||||
+ 3
|
||||
+ 6
|
||||
;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -149,6 +149,31 @@ foreach my $testSet (@htmlTextSets) {
|
|||
is($text, $testSet->{output}, $testSet->{comment});
|
||||
}
|
||||
|
||||
my @replacement_ids = ();
|
||||
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
|
||||
replacementId=>'new',
|
||||
searchFor=>':)',
|
||||
replaceWith=>'smiley.gif',
|
||||
});
|
||||
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
|
||||
replacementId=>'new',
|
||||
searchFor=>'[]',
|
||||
replaceWith=>'square brackets',
|
||||
});
|
||||
push @replacement_ids, $session->db->setRow("replacements","replacementId",{
|
||||
replacementId=>'new',
|
||||
searchFor=>'[IMAG]',
|
||||
replaceWith=>'IMAGE',
|
||||
});
|
||||
WebGUI::Test->addToCleanup(sub {
|
||||
foreach my $id (@replacement_ids) {
|
||||
$session->db->write('delete from replacements where replacementId=?',[$id]);
|
||||
}
|
||||
});
|
||||
|
||||
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');
|
||||
is(WebGUI::HTML::processReplacements($session, ':)'), 'smiley.gif', '... unbalanced paren is replaced');
|
||||
is(WebGUI::HTML::processReplacements($session, '[]'), 'square brackets', '... square brackets are replaced');
|
||||
is(WebGUI::HTML::processReplacements($session, '[IMAG]'), 'IMAGE', '... image sequence processed');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue