«+» 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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.