Subject: | $xml10_s_rx usage in Test::XML::Easy |
Date: | Tue, 11 Aug 2009 10:14:13 +0100 |
To: | bug-Test-XML-Easy [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
Test::XML::Easy uses $xml10_s_rx (from XML::Easy::Syntax) slightly
incorrectly. $xml10_s_rx matches a *sequence of one or more* whitespace
chars, but you've treated it as if it matched *exactly one* whitespace
char, risking exponential explosion in backtracking. Also, two of the
three places that you do whitespace matching will match on an empty
string and do a null substitution, whereas it would be more efficient
to only match a non-empty string. Incidentally, you should be using
the /o modifier to avoid repeated interpolation. So where you have
$comp_got_text =~ s/ \A (?:$xml10_s_rx)* //x;
you should instead have
$comp_got_text =~ s/ \A $xml10_s_rx //ox;
and likewise the other substitutions should be
$comp_got_text =~ s/ $xml10_s_rx \z//ox;
$comp_got_text =~ s/ $xml10_s_rx / /ogx;
-zefram