[EMAIL PROTECTED] (Randal L. Schwartz) writes: > >>>>> "me-01" == me-01 <[EMAIL PROTECTED]> writes: > > me-01> Hi, > me-01> URI::Escape uses the following code to set a subs function in uri_escape: > > me-01> if (defined $patn){ > me-01> unless (exists $subst{$patn}) { > me-01> # Because we can't compile the regex we fake it with a cached sub > me-01> (my $tmp = $patn) =~ s,/,\\/,g; > me-01> $subst{$patn} = > me-01> eval "sub {\$_[0] =~ s/([$tmp])/\$escapes{\$1}/g; }"; > me-01> Carp::croak("uri_escape: $@") if $@; > me-01> } > me-01> &{$subst{$patn}}($text); > me-01> } else { > me-01> # Default unsafe characters. RFC 2732 ^(uric - reserved) > me-01> $text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g; > me-01> } > > me-01> The problem with this is that if the eval fails for a bad pattern, > me-01> $subst{$patn} does still get set. so if the user has an eval somewhere > me-01> around the call to uri_escape and the program continues, on the next > me-01> call to uri_escape with that same pattern the "if" test will fail, > me-01> and he will get an error. Easily fixed of course by first assigning > me-01> to a temp var, and only assigning to $subst{$patn} after the croak test > > Or even just putting the assignment *inside* the eval: > > $abc = "foo"; > $badpat = "ab[c"; > eval "\$abc = sub {\$_[0] = s/($badpat)/\$escapes{\$1}/g; }";
The Randal way has now been applied. Thanks! Regards, Gisle