Skip to content

Commit

Permalink
Fix reserved chars to be based on RFC3986
Browse files Browse the repository at this point in the history
  • Loading branch information
titsuki committed Apr 7, 2018
1 parent 1a3c819 commit b636608
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.pod
Expand Up @@ -6,7 +6,7 @@ A Perl 6 module for encoding / decoding URIs

use URI::Encode;

# for encoding whole URIs, ignores reserved chars: #$&+,/:;=?@
# for encoding whole URIs, ignores reserved chars: :/?#[]@!$&'()*+,;=
my $encoded_uri = uri_encode('http://www.example.com/?name=john doe&age=54');

# encode every reserved char
Expand Down
2 changes: 1 addition & 1 deletion lib/URI/Encode.pm6
@@ -1,7 +1,7 @@
module URI::Encode:ver<0.05>
{
my $RFC3986_unreserved = rx/<[0..9A..Za..z\-.~_]>/;
my $RFC3986_reserved = rx/<[\!\+\#\$\&\+,\/\:;\=\?@]>/;
my $RFC3986_reserved = rx/<[:/?#\[\]@!$&'()*+,;=]>/;

my %escapes;
for (0..255) {
Expand Down
5 changes: 3 additions & 2 deletions t/Encode.t
Expand Up @@ -3,13 +3,14 @@ use Test;
use lib './lib';
use URI::Encode;

plan 22;
plan 23;

# encode
is uri_encode(" "), "%20%20", 'Encode " "';
is uri_encode("|abcå"), "%7Cabc%C3%A5", 'Encode "|abcå"';
is uri_encode("-.~_"), "-.~_", 'Encode -.~_';
is uri_encode(":/?#\[\]@!\$\&'()*+,;="), ":/?#\[\]@!\$\&'()*+,;=", 'Encode :/?#\[\]@!$&\'()*+,;=';
is uri_encode("abc"), "abc", 'Encode "abc"';
is uri_encode("~*'()"), "~%2A%27%28%29",'Encode "~*\'()"';
is uri_encode("<\">"), "%3C%22%3E", 'Encode "<\"';
is uri_encode("Hello World!"), "Hello%20World!", 'Encode "Hello World!"';
is uri_encode("http://perltricks.com/"), "http://perltricks.com/",
Expand Down

0 comments on commit b636608

Please sign in to comment.