Justudo has asked for the wisdom of the Perl Monks concerning the following question:

First time, first post, new monk Justudo has a problem. I'm trying to pass the original calling URL to the login procedure :
validateUser($ENV{'REQUEST_URI'});
Where the calling URL looks something like :
http://localhost/testdoc_scripts/upd?file_url=//testdoc_dir/t1.txt&fil +e_path=/u02/data/doc/test/t1.txt&43368
The validateUser calls the Login form as http://localhost/testdoc_scripts/login?request_uri=...<request-uri-value> . But the REQUEST_URI gets truncated as :
/testdoc_scripts/upd?file_url=//testdoc_dir/t1.txt
Why does the truncation occur after the first '&' in the Login URL ? Monks pls advise. thank u.

Replies are listed 'Best First'.
Re: REQUEST_URI from $ENV gets truncated
by LTjake (Prior) on Oct 17, 2002 at 11:31 UTC
    I'm not real sure about your $ENV problem, but using CGI.pm i can do the following:
    #!/usr/bin/perl -w use CGI; use strict; print $q->header, $q->url(-absolute=>1, -path=>1, -query=>1);
    I added ?file_url=//testdoc_dir/t1.txt&file_path=/u02/data/doc/test/t1.txt&43368 to the end of the URL which produced the following output:
    /cgi-bin/temp/self.cgi?file_url=%2F%2Ftestdoc_dir%2Ft1.txt&file_path=% +2Fu02%2Fdata%2Fdoc%2Ftest%2Ft1.txt
    HTH

    Update: got rid of s/// and used the url method with some extra params. Also, you'll note that &43368 gets thrown away. adding an equals sign afterwards seems to keep it. *shrug*

    Alternatively, you might write:
    print $q->url(-absolute=>1, -path=>1), '?', $ENV{QUERY_STRING};
    Which gives (note: unescaped URL)
    /cgi-bin/temp/self.cgi?file_url=//testdoc_dir/t1.txt&file_path=/u02/da +ta/doc/test/t1.txt&43368


    --
    Rock is dead. Long live paper and scissors!
Re: REQUEST_URI from $ENV gets truncated
by dws (Chancellor) on Oct 17, 2002 at 16:54 UTC
    The validateUser calls the Login form as http://localhost/testdoc_scripts/login?request_uri=...<request-uri-value> . But the REQUEST_URI gets truncated ...

    Assuming you mean that <request-uri-value> is actually $ENV{'REQUEST_URI'} (as passed to validateUser()), and that you're passing it as an argument to another CGI, then you need to encode that string for use as a CGI argument. See URI::Escape for how to do that correctly.

      I've never seen any beginner get it right using only URI::Escape. Much better to use URI directly and use the query_form call to do the right semi-escaping. You don't want to escape the ampersands between the fields, for example.

      I've posted examples of using URI with query_form here before.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.