[ic] Bugfix for Cart.pm, MaxQuantityField prefix
Jon Jensen
jon at endpoint.com
Mon May 2 21:42:49 UTC 2011
On Mon, 2 May 2011, Josh Lavin wrote:
> The patch is simple (the problem is the substitution caused prefix to be
> set to a '1', not the actual prefix):
>
> - my ($prefix) = $tab =~ s/^([=\?])//;
> - $prefix ||= '';
> + $tab =~ s/^([=\?])//;
> + my $prefix = $1 || '';
Josh,
That use of a regular expression match is not safe. The $1 will contain
the last successful match, even if the previous match failed, so you
always have to check for success of the regex match immediately
beforehand. Here's an illustration:
"howdy" =~ /(howd)y.*/;
my $corn = "dog";
$corn =~ /(fantastic)/;
my $prefix = $1 || '';
print "$prefix\n";
That will output "howd", not "".
Try something like this:
my $prefix = '';
$tab =~ s/^([=?])// and $prefix = $1;
(There's no need to escape ? in a character class [=?] since it's not
special there.)
Jon
--
Jon Jensen
End Point Corporation
http://www.endpoint.com/
More information about the interchange-users
mailing list