Subject: | Error in SCRIPT_NAME / PATH_INFO regex |
I noticed some "use of uninitialized value" warnings in the
perl core test suite that came from the tests of the CGI
module. The errors can be reproduced with the CPAN version,
too:
mhx@r2d2 $ make test
PERL_DL_NONLAZY=1 /usr/bin/perl5.8.7 "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/apache................ok
t/can...................ok
t/carp..................ok
t/cookie................ok
t/fast..................ok
7/7 skipped: FCGI not installed, cannot continue
t/form..................ok
t/function..............Use of uninitialized value in concatenation (.)
or string at (eval 7) line 7.
Use of uninitialized value in concatenation (.) or string at (eval 7)
line 7.
t/function..............ok
t/html..................ok
t/no_tabindex...........ok
t/pretty................ok
t/push..................ok
1/12 skipped: do_sleep() test may take a while
t/request...............ok 1/33Use of uninitialized value in
concatenation (.) or string at (eval 7) line 7.
Use of uninitialized value in concatenation (.) or string at (eval 7)
line 7.
t/request...............ok
t/start_end_asterisk....ok
t/start_end_end.........ok
t/start_end_start.......ok
t/switch................ok
t/util-58...............ok
t/util..................ok
All tests successful, 8 subtests skipped.
Files=18, Tests=502, 3 wallclock secs ( 2.50 cusr + 0.28 csys = 2.78 CPU)
With a recent version of bleadperl, you can see which
variables are uninitialized:
mhx@r2d2 ~/src/perl/modules/CGI.pm-3.19 $ bleadperl -Mblib t/function.t
1..31
[...]
ok 12
Use of uninitialized value $\ in concatenation (.) or string at (eval 9)
line 7.
ok 13
Use of uninitialized value $\ in concatenation (.) or string at (eval 9)
line 7.
ok 14
[...]
The problem is this line of code in CGI.pm:
$raw_script_name =~ s/\Q$raw_path_info$\E//;
This is parsed as "$\ E" instead of (what I assume you were
expecting) "$ \E". Fortunately, the \E isn't required in
this case, so the following patch will fix the problem.
--- CGI.pm.orig 2006-04-23 02:55:35.000000000 +0200
+++ CGI.pm 2006-04-23 05:01:45.000000000 +0200
@@ -2778,7 +2778,7 @@
my $raw_path_info = $ENV{PATH_INFO} || '';
my $uri = unescape($self->request_uri) || '';
- $raw_script_name =~ s/\Q$raw_path_info$\E//;
+ $raw_script_name =~ s/\Q$raw_path_info$//;
my @uri_double_slashes = $uri =~ m^(/{2,}?)^g;
my @path_double_slashes = "$raw_script_name $raw_path_info" =~
m^(/{2,}?)^g;
Regards,
Marcus