Subject: | url function return extra '?' or empty query string |
When using $q->url in a CGI script that weas invoked with an empty query string:
http://mysite/cgi-bin/prog?
The result URL will incorrectly include the '?'.
According to the perldoc, the '?' (and the query string) will be included only if the parameter query is set. The problem is caused by line 2634 (CGI.pm 3.14), which will eliminate the '?' only if there are some characters after the '?'.
2633 my $uri = $rewrite && $request_uri ? $request_uri : $script_name;
2634 $uri =~ s/\?.+$// if defined $query_str;
2635 $uri =~ s/$path$// if defined $path; # remove path from URI
The fix is to use 's/\?.*$//' to filter out the query string.
VERSION=3.14 $Id: CGI.pm,v 1.194 2005/12/06 22:12:56 lstein Exp $
INPUT=/~yair/x.cgi?
URL=http://ybgweb/~yair/x.cgi?
VERSION=3.14 $Id: CGI.pm,v 1.194 2005/12/06 22:12:56 lstein Exp $
INPUT=/~yair/x.cgi?
URL=http://ybgweb/~yair/x.cgi?
Test Program:
#! /usr/local/bin/perl
use CGI ;
my $q = new CGI() ;
print $q->header('text/plain') ;
print "VERSION=$CGI::VERSION $CGI::revision\n" ;
print "INPUT=$ENV{REQUEST_URI}\n";
print "URL=", $q->url, "\n" ;