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
|
7.10.22
|
||||||
- rfe #12207: Thingy. Field_name info returned by www_editThingDataSaveViaAjax
|
- rfe #12207: Thingy. Field_name info returned by www_editThingDataSaveViaAjax
|
||||||
- fixed #12206: Bad Subscription Groups in Duplicated Threads
|
- fixed #12206: Bad Subscription Groups in Duplicated Threads
|
||||||
|
- fixed #12208: replacements don't work
|
||||||
|
|
||||||
7.10.21
|
7.10.21
|
||||||
- added #9668 extension template variable to attachment loops for the following assets:
|
- added #9668 extension template variable to attachment loops for the following assets:
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,11 @@ sub processReplacements {
|
||||||
}
|
}
|
||||||
foreach my $searchFor (keys %{$replacements}) {
|
foreach my $searchFor (keys %{$replacements}) {
|
||||||
my $replaceWith = $replacements->{$searchFor};
|
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;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
t/HTML.t
33
t/HTML.t
|
|
@ -65,7 +65,7 @@ my @filterSets = (
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputText => q!<p>Paragraph</p>^H();!,
|
inputText => q!<p>Paragraph</p>^H();!,
|
||||||
output => q!Paragraph ^H();!,
|
output => q|Paragraph ^H();|,
|
||||||
type => 'all',
|
type => 'all',
|
||||||
comment => 'all filters macros and HTML',
|
comment => 'all filters macros and HTML',
|
||||||
},
|
},
|
||||||
|
|
@ -83,12 +83,12 @@ my @filterSets = (
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputText => q! !,
|
inputText => q! !,
|
||||||
output => q!&nbsp;!,
|
output => q|&nbsp;|,
|
||||||
type => 'xml',
|
type => 'xml',
|
||||||
comment => 'xml, ',
|
comment => 'xml, ',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputText => q!> < "!,
|
inputText => q|> < "|,
|
||||||
output => q!> < "!,
|
output => q!> < "!,
|
||||||
type => 'xml',
|
type => 'xml',
|
||||||
comment => 'xml, other characters',
|
comment => 'xml, other characters',
|
||||||
|
|
@ -129,7 +129,7 @@ my @htmlTextSets = (
|
||||||
my $numTests = scalar @filterSets
|
my $numTests = scalar @filterSets
|
||||||
+ scalar @macroParamSets
|
+ scalar @macroParamSets
|
||||||
+ scalar @htmlTextSets
|
+ scalar @htmlTextSets
|
||||||
+ 3
|
+ 6
|
||||||
;
|
;
|
||||||
|
|
||||||
plan tests => $numTests;
|
plan tests => $numTests;
|
||||||
|
|
@ -149,6 +149,31 @@ foreach my $testSet (@htmlTextSets) {
|
||||||
is($text, $testSet->{output}, $testSet->{comment});
|
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, 'grass'), 'grass', 'processReplacements: grass is not replaced');
|
||||||
is(WebGUI::HTML::processReplacements($session, 'shitake'), 'shitake', '... shitake 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, '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