Skip to content

Commit

Permalink
resolve #161 - add env_query_string method
Browse files Browse the repository at this point in the history
as the query_string method returns the query string after potential
changes to it, the env_query_string can be used to get the query
string in its untouched original form as set in the environment
variable
  • Loading branch information
leejo committed Mar 1, 2015
1 parent 035b28d commit 085db3b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
- CGI::Carp now has $CGI::Carp::FULL_PATH for displaying the full path to the
offending script in error messages

- CGI now has env_query_string() for getting the value of QUERY_STRING from the
environment and not that fiddled with by CGI.pm (which is what query_string()
does) (GH #161)

[ SPEC / BUG FIXES ]
- Add the multi_param method to :cgi export (thanks to xblitz for the patch
and tests. GH #167)
Expand Down
6 changes: 5 additions & 1 deletion lib/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ sub _set_binmode {
cookie Dump raw_cookie request_method query_string Accept user_agent remote_host content_type
remote_addr referer server_name server_software server_port server_protocol virtual_port
virtual_host remote_ident auth_type http append save_parameters restore_parameters param_fetch
remote_user user_name header redirect import_names put Delete Delete_all url_param cgi_error
remote_user user_name header redirect import_names put Delete Delete_all url_param cgi_error env_query_string
/ ],
':netscape' => [qw/blink fontsize center/],
':ssl' => [qw/https/],
Expand Down Expand Up @@ -2906,6 +2906,10 @@ sub query_string {
return join($USE_PARAM_SEMICOLONS ? ';' : '&',@pairs);
}

sub env_query_string {
return (defined $ENV{'QUERY_STRING'}) ? $ENV{'QUERY_STRING'} : undef;
}

#### Method: accept
# Without parameters, returns an array of the
# MIME types the browser accepts.
Expand Down
3 changes: 3 additions & 0 deletions lib/CGI.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,9 @@ state with query_string():
The behavior of calling query_string is currently undefined when the HTTP method is
something other than GET.

If you want to retreived the query string as set in the webserver, namely the
environment variable, you can call env_query_string()

=head2 Obtaining the script's url

$full_url = url();
Expand Down
2 changes: 1 addition & 1 deletion t/export.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

use Test::More tests => 178;
use Test::More tests => 179;

BEGIN{ use_ok('CGI', ':all'); }

Expand Down
6 changes: 4 additions & 2 deletions t/function.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/local/bin/perl -w

BEGIN {$| = 1; print "1..32\n"; }
BEGIN {$| = 1; print "1..33\n"; }
END {print "not ok 1\n" unless $loaded;}
use Config;
use CGI (':standard','keywords');
Expand Down Expand Up @@ -105,4 +105,6 @@ test(30, !charset("") && header() eq "Content-Type: text/html${CRLF}${CRLF}", "E

test(31, header(-foo=>'bar') eq "Foo: bar${CRLF}Content-Type: text/html${CRLF}${CRLF}", "Custom header");

test(32, start_form(-action=>'one',name=>'two',onsubmit=>'three') eq qq(<form method="post" action="one" enctype="multipart/form-data" name="two" onsubmit="three">), "initial dash followed by undashed arguments")
test(32, start_form(-action=>'one',name=>'two',onsubmit=>'three') eq qq(<form method="post" action="one" enctype="multipart/form-data" name="two" onsubmit="three">), "initial dash followed by undashed arguments");
$ENV{QUERY_STRING} ='game=chess&game=checkers&weather=dull';
test(33,env_query_string() eq $ENV{QUERY_STRING},"CGI::env_query_string()");

0 comments on commit 085db3b

Please sign in to comment.