«+» is a reserved character.
Of those, the spec says
If data for a URI component would conflict with a reserved character's purpose as a delimiter, then the conflicting data must be percent-encoded before the URI is formed.
Historically, «+» has been used as an encoding for spaces in the query portion of HTTP URIs. As such, it needs to be encoded in the query portion of HTTP URIs if nothing else.
For example, when you submit a query of «c++» to Google using Firefox and Chrome, they encode the URL as https://www.google.com/search?q=c%2B%2B&....
URL::Encode doesn't know if it's a path component (where «+» isn't special) or a query component (where it is), but it's usually used for query components, so it treats «+» as the encoding of a space, and thus decodes «c++» into «c␠␠»
URI, being more context aware, can provide a more appropriate decoding.
$ perl -e' use v5.14; use URI qw( ); my $uri = URI->new( "https://example.com/a+b?c+d=e+f" ); say for $uri->path, $uri->query_form; ' /a+b c d e f
In reply to Re: why URL::Encode deliberately mistreat '+'
by ikegami
in thread why URL::Encode deliberately mistreat '+'
by vincentaxhe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |