Skip to content
Permalink
Browse files

Fix replacements (again). Add tests to test words and sequences with …

…punctuation. Fixes bug #12208.
  • Loading branch information...
perlDreamer committed Aug 1, 2011
1 parent a3a894b commit 662f6bf65c262aef3a0d912eff0946d48c7ff3a9
Showing with 35 additions and 5 deletions.
  1. +1 −0 docs/changelog/7.x.x.txt
  2. +5 −1 lib/WebGUI/HTML.pm
  3. +29 −4 t/HTML.t
@@ -1,6 +1,7 @@
7.9.34
- fixed #12206: Bad Subscription Groups in Duplicated Threads
- fixed #12202: JsonTable refers to unexistent YUI file
- fixed #12208: replacements don't work

7.9.33
- fixed #12188: Thingy broken after upgrade to 7.9.32-stable
@@ -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;
}
@@ -65,7 +65,7 @@ my @filterSets = (
},
{
inputText => q!<p>Paragraph</p>^H();!,
output => q!Paragraph &#94;H();!,
output => q|Paragraph &#94;H();|,
type => 'all',
comment => 'all filters macros and HTML',
},
@@ -83,12 +83,12 @@ my @filterSets = (
},
{
inputText => q!&nbsp;!,
output => q!&#x26;nbsp;!,
output => q|&#x26;nbsp;|,
type => 'xml',
comment => 'xml, &nbsp;',
},
{
inputText => q!> < "!,
inputText => q|> < "|,
output => q!&#x3E; &#x3C; &#x22;!,
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');

0 comments on commit 662f6bf

Please sign in to comment.
You can’t perform that action at this time.