Bug 188441 - url(-relative=>1) is broken in CGI.pm
url(-relative=>1) is broken in CGI.pm
Product: Fedora
Classification: Fedora
Component: perl (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Robin Norwood
David Lawrence
Depends On:
Blocks: 199152
  Show dependency treegraph
Reported: 2006-04-09 22:47 EDT by Bruno Wolff III
Modified: 2007-11-30 17:11 EST (History)
2 users (show)

See Also:
Fixed In Version: 5.8.8-5
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-10-04 14:40:58 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
CGI.pm (3.15) fixed to use rewritten REQUEST_URI in url() if rewrite!=0 (236.56 KB, text/plain)
2006-04-12 18:54 EDT, Jason Vas Dias
no flags Details

  None (edit)
Description Bruno Wolff III 2006-04-09 22:47:18 EDT
Description of problem:
url(-relative) no longer returns the original relative path before rewrites.
This used to work in FC4.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Set up a redirect in your .htaccess file such as:
RewriteEngine On
RewriteBase /
RewriteRule ^testabc.cgi$ test.cgi
2. Create a test perl script, test.cgi such as:

use CGI qw/:standard -no_xhtml/;

print "Content-type: text/plain\n\n";
print url(-relative=>1), "\n";
print url(-absolute=>1), "\n";

3. Look at the web page /testabc.cgi
Actual results:

Expected results:

Additional info:
Comment 1 Jason Vas Dias 2006-04-12 17:16:42 EDT
Hmmm, this does not seem to be a problem with perl's CGI:: module -

I put your rewrite rule in /etc/httpd/conf/httpd.conf's /var/www/cgi-bin/ 
'Directory' entry, from the standard config from a clean install of 
httpd-2.2.0-6 , so it now reads:
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options FollowSymLinks
    Order allow,deny
    Allow from all
    RewriteEngine On
    RewriteBase /cgi-bin
    RewriteRule ^testabc.cgi$ test.cgi

NOTE: before the server would process the rewrite rule, it insisted that
the FollowSymLinks or FollowSymLinks owner option be specified - without
one of these options enabled, rewrite rules will be ignored.

Then your example test.cgi script works as expected, producing the output:

Perhaps your http server is not loading your .htaccess file correctly /
doesn't allow the FollowSymLinks or RewriteRule options ?

I'm CC-ing the httpd maintainer on this - perhaps he could shed some light on
why the rewrite rule might not be taking effect.

If the rewrite rule is correctly applied, the perl CGI module seems to have
no problem with url(-relative=>1) / url(-absolute=>1) .
Comment 2 Jason Vas Dias 2006-04-12 17:49:09 EDT
Sorry - my mistake - I was looking at the wrong output - it does produce :

This is a CPAN CGI module bug: 

I'll try out the patch from the above bug (now in CGI 3.17) and see if it 
fixes the problem - if so, it can go into the next perl-5.8.8-6+ release.
Comment 3 Jason Vas Dias 2006-04-12 18:53:11 EDT
OK, I now see the problem - CGI.pm-3.15 has a new "-rewrite" sub url() parameter,
which, if 0, is meant to make url() return the "$SCRIPT_NAME", not the
"$REQUEST_URI". It seems the programmer applies this logic only in the
case of '-absolute=>1', NOT '-relative=>1'. Yes, this seems like a bug
to me - and is still in the latest 3.17 version.
Please try out the attached CGI.pm which fixes the problem - if it works OK,
I'll submit it with the next perl-5.8.8-6 version.
Comment 4 Jason Vas Dias 2006-04-12 18:54:20 EDT
Created attachment 127678 [details]
CGI.pm (3.15) fixed to use rewritten REQUEST_URI in url() if rewrite!=0
Comment 5 Jason Vas Dias 2006-04-12 18:55:57 EDT
Sorry, should have mentioned: copy the above CGI.pm attachment to 
/usr/lib/perl5/5.8.8/CGI.pm to test.
Comment 6 Bruno Wolff III 2006-04-12 22:26:45 EDT
I tried this out and it looks like it is working. Thanks.
Comment 7 Jason Vas Dias 2006-04-13 16:30:17 EDT
Thanks for the testing. The fix is now checked into CVS and will go into the 
next perl-5.8.8-6 release. 
Upstream CPAN CGI.pm bug raised: [rt.cpan.org #18692]
Comment 8 Fedora Update System 2006-06-05 17:00:38 EDT
perl-5.8.8-5 has been pushed for fc5, which should resolve this issue.  If these problems are still present in this version, then please make note of it in this bug report.
Comment 9 Robin Norwood 2006-10-01 19:33:08 EDT
assigning to rnorwood@redhat.com

Note You need to log in before you can comment on or make changes to this bug.