Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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("http://www.foo.com?data=".uri_escape("12 34+56")); #sen +t as: data=12%2034%2B12, both space and "+" are escaped. my $res2 = get("http://www.foo.com?data=12 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/URI.pm:76): $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.

In reply to LWP and URI escape by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found