Subject: | StatelessProxy: red flag on regular expression usage |
Hi,
I was perusing the code for Net::SIP::StatelessProxy and noticed
something that could lead to nasty bugs. In particular:
if ( $to =~m{^(.*?)(\w+)(\@.*)}
&& ( my $back = invoke_callback( $rewrite_contact,$2 ) )) {
$to = $1.$back;
relies on the fact that the callback does not modify $1, i.e. it does
not use capturing regexes. I'd rather rewrite it like this (note: not
tested):
if ( ( my ($pre, $name, $rest) = $to =~ m{^(.*?)(\w+)(\@.*)} )
&& ( my $back = invoke_callback( $rewrite_contact, $2 ) ) ) {
$to = $pre . $back;
This ensures that $1 can be modified at will, while retaining the
captured value in $pre.
Hope this helps,
Flavio.