[RFH] t9500 failing???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Suddenly t9500.70 has started failing for me in my local environment
(but $Corp IT folks control pretty much which version of base software
is installed and updated at what time, once I choose "I want to do CGI
in Perl" by selecting the libcgi-pm-perl module, I am not sure from
which version the thing was updated from.  The Debian version claims
to be 4.62-1.

It fails with path-info test, starting at t9500.70 with extra
warning in the log.  This code

	if ($path_info) {
		# $path_info has already been URL-decoded by the web server, but
		# $my_url and $my_uri have not. URL-decode them so we can properly
		# strip $path_info.
		$my_url = unescape($my_url);
		$my_uri = unescape($my_uri);
		if ($my_url =~ s,\Q$path_info\E$,, &&
		    $my_uri =~ s,\Q$path_info\E$,, &&
		    defined $ENV{'SCRIPT_NAME'}) {
			$base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
		}
	}

before it calls unescape(), I know $my_url is a
http://localhost/gitweb.cgi and after it calls unescape, it becomes
undefined.  That will trigger a "Use of uninitialized value $my_url
in substitution (s///)" warning.

unescape comes from CGI::Util because we do

	use CGI::Util qw(unescape);

early in the program.

As a workaround I locally have the attached patch to disable calling
CGI::Util::unescape implicitly as a sub, and instead make an
explicit call to it as a class method, and it seems to make the
tests pass.  Please do not ask me why it works---the reason why I am
posting this message is to find somebody who can explain it to me ;-)

The "unescape" thing in CGI::Util.pm begins with the standard
boilerplate that lets you call it as a plain-vanilla sub as well as
a class method, like so:

    # unescape URL-encoded data
    sub unescape {
      shift() if @_ > 0 and (ref($[0]) || (defined $[1] && $_[0] eq $CGI::DefaultClass));

but it seems that it has been that way since 2009, so it does not
explain why it started breaking for me all of sudden, even though
it _is_ curious that its counterpart in the same file, escape,
starts slightly differently to (presumably) achieve the same thing.

    sub escape {
      # If we being called in an OO-context, discard the first argument.
      shift() if @_ > 1 and ( ref($[0]) || (defined $[1] && $_[0] eq $CGI::DefaultClass));

Notice that the former does "shift" as long as there is even a
single argument, while the latter does so only when there are at
least two arguments.  Both presumably would take a single argument,
the string to either escape or unescape, and the shift is presumably
to shift away the class object if they are called as class methods,
so the guard at the beginning of unscape looks suspect, but I am not
a Perl person, and as I said, it seems that the code has been that
way since 2009, so it is very likely that I am barking up a wrong
tree.

Anyway.  TIA for whoever explains the solution to this puzzle to me.


 gitweb/gitweb.perl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git c/gitweb/gitweb.perl w/gitweb/gitweb.perl
index ccd14e0e30..a0a8b79ef4 100755
--- c/gitweb/gitweb.perl
+++ w/gitweb/gitweb.perl
@@ -13,7 +13,7 @@
 # handle ACL in file access tests
 use filetest 'access';
 use CGI qw(:standard :escapeHTML -nosticky);
-use CGI::Util qw(unescape);
+use CGI::Util qw();
 use CGI::Carp qw(fatalsToBrowser set_message);
 use Encode;
 use Fcntl ':mode';
@@ -22,6 +22,11 @@
 use Time::HiRes qw(gettimeofday tv_interval);
 use Digest::MD5 qw(md5_hex);
 
+sub unescape {
+	my $url = shift;
+	return CGI::Util->unescape($url);
+}
+
 binmode STDOUT, ':utf8';
 
 if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux