Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Unwanted parameter when executing CGI scripts

by Anonymous Monk
on Jan 05, 2013 at 00:05 UTC ( #1011745=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED] Unwanted parameter when executing CGI scripts

Now, when calling such scripts without any parameters (i.e. without query string after the script name / path), the scripts are seeing an unwanted parameter "Keywords" (which does not have a value).

Trivial to test

$ perl -MData::Dump -MCGI -e " dd( CGI->new(q{?noampernoequal}) )" bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["keywords"], "escape" => 1, "param" => { keywords => ["?noampernoequal"] }, "use_tempfile" => 1, }, "CGI") $ perl -MCGI -e " print CGI->new(q{?noampernoequal})->param " keywords $ perl -MCGI -e " print CGI->new(q{?noampernoequal})->keywords " ?noampernoequal $ perl -MCGI -e " print for CGI->new(q{?noampernoequal})->keywords " ?noampernoequal $ perl -MCGI -e " print for CGI->new(q{?a=b;noampernoequal})->keywords + "

Easy to remove

use Data::Dump; use CGI; my $q = CGI->new( q{?noampernoequal}); dd $q; dd $q->param; dd $q->keywords; $q->delete('keywords') if $q->keywords; dd $q->param; dd $q; __END__ bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => ["keywords"], "escape" => 1, "param" => { keywords => ["?noampernoequal"] }, "use_tempfile" => 1, }, "CGI") "keywords" "?noampernoequal" () bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".parameters" => [], "escape" => 1, "param" => {}, "use_tempfile" => 1, }, "CGI")

I don't think I've ever used this feature in 10 years :)


Comment on Re: Unwanted parameter when executing CGI scripts
Select or Download Code
Re^2: Unwanted parameter when executing CGI scripts
by Nocturnus (Sexton) on Jan 05, 2013 at 08:01 UTC

    Well, I think that

    $q->delete('keywords') if $q->keywords;

    will delete the "keywords" parameter in every case, i.e. regardless if it has been automatically generated by CGI.pm or if it actually has been passed via query string. But as I wrote in my initial post, I would like to remove it only in the former case (for example when the script has been called without any parameters), but I want to keep it if it has been "actively" passed via query string.

    Thus, I think I really have to check if there is no query string, or if there is a query string which does not contain = or &, and remove the "keywords" parameter accordingly.

    Anyways, thank you very much for your suggestion. I have learned a much from how you use dd and Data::Dump.

    Regards,

    Nocturnus

      will delete the "keywords" parameter in every case, i.e. regardless if it has been automatically generated by CGI.pm

      You're wrong :)

      I didn't read past that statement, but if you need convincing you are wrong, read the CGI.pm source

        OK, I am sorry. You are right (no need to read the source code, only the documentation ...).

        Interestingly, the delete method seems to remove the respective entry only from $q->params, but not from $q->url_params (now guess which of the two I (have to) use). This is not documented in the CGI.pm documentation as far as I have seen.

        But that's not a big problem. I just will use one of the usual methods to remove the respective hash entry.

        Besides this, I didn't get your code to work like I want. Perhaps I have another error, but at the moment it seems that $q->keywords is empty if the script is called without any parameters, so $q -> keywords evaluates to false in this case, and the code doesn't get executed anyways.

        Regards,

        Nocturnus

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011745]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-07-04 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls