Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

CGI::Vars weirdness

by Anonymous Monk
on Apr 04, 2008 at 01:29 UTC ( [id://678308]=perlquestion: print w/replies, xml ) Need Help??

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

hi monks, I have a problem with CGI::Vars. my $vars = $cgi->Vars; print STDERR "CGI VARS: " . Dumper($vars) . "\n"; When I print out the key/value pairs of Vars, I see that '+' signs, wh +ich must have been in the values have been translated to spaces:(. Th +e rest of the characters are still excaped and they should have been. + Do you know why this weird behavior is showing and if there is a way + that I could view the values in their raw format(no weird "+" sign +substitutions)? I do not want to to run a regex that will substitute the " " with a "+ +". Thank you very much!

Replies are listed 'Best First'.
Re: CGI::Vars weirdness
by Joost (Canon) on Apr 04, 2008 at 02:04 UTC
    + is a valid encoding for space in the CGI/HTML form specs. IOW what you see is expected, and/or your input isn't supplied according to the specs.

    update: see this:

    #!/usr/bin/perl -w use strict; use CGI; print CGI->header(); print q(<form><input type="text" name="stuff"><input type="submit"></f +orm>); my %vars = CGI->new->Vars(); print "$_ => '$vars{$_}'<br>" for sort keys %vars;
    entering a + there in any conforming browser should give a + as the result.

      That is exatly what I want to see. When I enter a '+', I want to see t +he '+' in the CGI::Vars:( Alas! I did however forget to mention something important. I am using an Aja +x callback to submit the form. Could that be causing the problem?? <input type="button" name="mysubmit" value="Submit" onClick="myFunc([' +mytool', 'foo', 'bar'], ['result'], 'POST'); "/> Thanks again!

        Most likely, you will either need to properly encode your entities for the request (escape() function) or use a Ajax framework that properly encoded the entities for the request.

        As an aside, please put your "human" text into <p>...</p> tags and only your code into <code>...</code> tags. That way, it is far better readable for everybody.

Re: CGI::Vars weirdness
by gam3 (Curate) on Apr 04, 2008 at 02:20 UTC
    I am confused by you problem.

    If you would like to have the QUERY_STRING directly you can parse $ENV{QUERY_STRING};

    my @values = split(/&/,$ENV{QUERY_STRING}); foreach my $i (@values) { my ($name, $value) = split(/=/, $i); push(@{$keys{$name}}, $value); }
    Note that this has a slightly different structure that the structure ruturned by CGI::Vars.
    -- gam3
    A picture is worth a thousand words, but takes 200K.

      The semicolon is also a valid separator for key-value pairs in URL-encoded query strings... but don't parse query strings by hand. You'll get it wrong.

        Not quite. ";" is a valid separator for HTTP URLs, but not for application/x-www-form-urlencoded (i.e. form) data.

        In other words, you may assign URLs any meaning you wish to ";" in URLs to resources you control, but it's by no means equivalent to "&" unless you choose it to be for those resources. You shouldn't impose your choice as fact onto others.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-20 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found