Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

"+" stripped from CGI params

by citromatik (Curate)
on Dec 21, 2007 at 13:35 UTC ( [id://658444]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all

I'm pretty sure that I'm missing something evident, but I can't see what. Why is the "+" character stripped from the CGI parameters?

use strict; use warnings; use CGI; my $q = new CGI; my $data = $q->param("gff"); print "$data\n";

For debugging I'm running the script from the command line :

perl perlcgi/getPlot.pl gff='kk_+ kk_-'

The output that I obtain is:

kk_ kk_-

Thanks in advance!

citromatik

Replies are listed 'Best First'.
Re: "+" stripped from CGI params
by jettero (Monsignor) on Dec 21, 2007 at 13:41 UTC
    I think, traditionally, the '+' represents a space. I'm not sure what standard dictates this, but it seems to be the case.

    You can replace the '+' with a '%2b' to avoid it. Happily, CGI can do this for you if necessary:

    my $encoded = $cgi_obj->escape("kk_+kk_");
    .

    -Paul

      I think, traditionally, the '+' represents a space. I'm not sure what standard dictates this, but it seems to be th

      I bet you'll find that the URI spec dictates that it must be escaped when it doesn't have a special meaning to the URI, as is the case here.

      One such special meaning was the seperation of keywords in a ISINDEX query (script.cgi?these+are+keyworkds). The query would have had whitespace at those spots, so it was common to replace +s with spaces.

        Yep :) "Within the query string, the plus sign is reserved as shorthand notation for a space. Therefore, real plus signs must be encoded. This method was used to make query URIs easier to pass in systems which did not allow spaces."
Re: "+" stripped from CGI params
by hawtin (Prior) on Dec 22, 2007 at 13:56 UTC

    I would suspect that this has to do with the different options for the form's enctype when the method is POST. This controls the way the parameters are delivered to CGI, from memory:

    • not-defined => "param1=one+value¶m2=another+val"
    • "text/plain" => "param1=one value param2=another val"
    • "multipart/form-data" => "param1=one value\nparam2=another val\n"

    My guess would be that since the default is to replace all spaces with "+" the CGI parameter processing by default does the reverse

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://658444]
Approved by jettero
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found