Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

LWP and URI escape

by johnnywang (Priest)
on Mar 02, 2007 at 23:05 UTC ( #602977=perlquestion: print w/replies, xml ) Need Help??
johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm confused/puzzled by how LWP handles URI escapes vs. URI::Escape. Say I have a form parameter named "data" with value "12 34+56".
use strict; use URI::Escape: use LWP:Simple; my $res = get("".uri_escape("12 34+56")); #sen +t as: data=12%2034%2B12, both space and "+" are escaped. my $res2 = get(" 34+56")); # sent as: date=1 +2%2034+56, i.e. space is escaped, but "+" is not.
I was expecting get() to also escape "+" for me. After stepping through the code, I see that LWP::Simple::get() does call something like uri_escape:
# in URI::_init(C:/Perl/site/lib/ $str =~ s/([^$uric\#])/$URI::Escape::escapes{$1}/go; # where $uric is: # \;\/\?\:\@\&\=\+\$\,\[\]A-Za-z0-9\-_\.\!\~\*\'\(\)%
where you can see "+" is not escaped, plus a few others. URI::Escape::uri_escape is implemented as:
$text =~ s/([^A-Za-z0-9\-_.!~*'()])/$escapes{$1}/g;
which would escape "+". My question is why URI::Escape is escaping more than what get() does (via URI::_init)? or why get() doesn't do the "appropriate" escaping? is the best practice to escape everything before sending to get() rather than relying on its escaping? how about UserAgent::post? will it escape its values completely? or am I missing something? Thanks.

Replies are listed 'Best First'.
Re: LWP and URI escape
by Joost (Canon) on Mar 02, 2007 at 23:17 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://602977]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-01-17 10:06 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (198 votes). Check out past polls.