Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Characters that cannot be encoded with query_param #67

Open
ghost opened this issue Dec 6, 2019 · 2 comments
Open

Characters that cannot be encoded with query_param #67

ghost opened this issue Dec 6, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 6, 2019

The following strings are not encoded in query_param.
! * () '
The code is shown below.

perl -le '
    use strict;
    use URI;
    use URI::QueryParam;

    my $domain = q{https://hoge.com};
    # chr(hex(27)) is single quote
    my $param = {foo => q{!*()}.chr(hex(27))};

    my $uri = URI->new($domain);
    $uri->query_param( %$param );
    print "encoded by URI::QueryParam: ".$uri->as_string;
';
encoded by URI::QueryParam: https://hoge.com?foo=!*()'

Shouldn't it be encoded if it conforms to RFC3986?
Or is there a way to encode the above characters using query_param?

@haarg
Copy link
Member

haarg commented Sep 25, 2023

I don't see anything in RFC3986 which would require those characters to be percent encoded.

The URL spec is possibly a more useful reference. The query part of a URL is not required to have the characters !, (, ), or * encoded. But when producing a query string, the spec states:

The application/x-www-form-urlencoded percent-encode set contains all code points, except the ASCII alphanumeric, U+002A (*), U+002D (-), U+002E (.), and U+005F (_).

According to this, !, ), and ( should be encoded when using query_param, but * should not be.

@kartiksubbarao
Copy link

@haarg In the URL spec, I see that ' should be percent-encoded as well, for http, https, file, ws, and wss URLs (these are called special schemes by the spec):

The special-query percent-encode set is the query percent-encode set and U+0027 (').

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants