Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 16343
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: LDS [...] cpan.org
Requestors: yair.lenga [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: url function return extra '?' or empty query string
Download (untitled) / with headers
text/plain 1.1k
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" ;
From: jbw [...] jbw.pl
Download (untitled) / with headers
text/plain 809b
[guest - Wed Dec 7 10:20:38 2005]: This is tragic! It screwed up hundrets of my CGIs. IMO the function script_name() makes troubles. We see in CGI.pm: sub script_name { my ($self,@p) = self_or_default(@_); if (@p) { $self->{'.script_name'} = shift; } elsif (!exists $self->{'.script_name'}) { my ($script_name,$path_info) = $self->_name_and_path_from_env(); $self->{'.script_name'} = $script_name; } return $self->{'.script_name'}; } But some time ago we saw something less sophisticated, but more working: sub script_name { return $ENV{'SCRIPT_NAME'} if defined($ENV{'SCRIPT_NAME'}); # These are for debugging return "/$0" unless $0=~/^\//; return $0; } When I replaced function body with this older version, all my scripts again works good.
Download (untitled) / with headers
text/plain 1.2k
On Wed Dec 07 10:20:38 2005, guest wrote: Show quoted text
> 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 Show quoted text
> : $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" ;
Download (untitled) / with headers
text/plain 110b
This was fixed in 3.15: 1. Remove extraneous "?" from self_url() when URI contains a ? but no query string.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.