Tests and escaping for unicode characters
Signed-off-by: Charlie Garrison <cngarrison@gmail.com>master
parent
aa345a7f0a
commit
6b4653b790
|
@ -2,7 +2,7 @@ package DDG::Goodie::URLEncode;
|
|||
# ABSTRACT: Displays the percent-encoded url.
|
||||
|
||||
use DDG::Goodie;
|
||||
use URI::Escape::XS qw(encodeURIComponent);
|
||||
use URI::Escape qw(uri_escape);
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
|
@ -29,7 +29,7 @@ handle remainder => sub {
|
|||
|
||||
return unless $in;
|
||||
|
||||
my $encoded_url = encodeURIComponent($in);
|
||||
my $encoded_url = uri_escape($in);
|
||||
|
||||
my $text = "Percent-encoded URL: $encoded_url";
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
|
@ -101,6 +102,14 @@ ddg_goodie_test(
|
|||
result => 'https://duckduckgo.com/'
|
||||
}
|
||||
),
|
||||
'%E4%F6%FC' => test_zci(
|
||||
"URL Decoded: äöü",
|
||||
structured_answer => {
|
||||
input => ['%E4%F6%FC'],
|
||||
operation => 'URL decode',
|
||||
result => 'äöü'
|
||||
}
|
||||
),
|
||||
'%20' => test_zci(
|
||||
'URL Decoded: Space',
|
||||
structured_answer => {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
|
@ -68,20 +69,29 @@ ddg_goodie_test(
|
|||
),
|
||||
|
||||
'urlescape https://example.org/the answer to "[life], (the universe) .and. <everything>"' => test_zci(
|
||||
"Percent-encoded URL: https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22",
|
||||
"Percent-encoded URL: https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20%28the%20universe%29%20.and.%20%3Ceverything%3E%22",
|
||||
structured_answer => {
|
||||
input => ['https://example.org/the answer to "[life], (the universe) .and. <everything>"'],
|
||||
operation => 'URL percent-encode',
|
||||
result => 'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22'
|
||||
result => 'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20%28the%20universe%29%20.and.%20%3Ceverything%3E%22'
|
||||
}
|
||||
),
|
||||
|
||||
'www.heroku.com/{rawwr!@#$%^&*()+=__} escapeurl' => test_zci(
|
||||
"Percent-encoded URL: www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D",
|
||||
"Percent-encoded URL: www.heroku.com%2F%7Brawwr%21%40%23%24%25%5E%26%2A%28%29%2B%3D__%7D",
|
||||
structured_answer => {
|
||||
input => ['www.heroku.com/{rawwr!@#$%^&*()+=__}'],
|
||||
operation => 'URL percent-encode',
|
||||
result => 'www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D',
|
||||
result => 'www.heroku.com%2F%7Brawwr%21%40%23%24%25%5E%26%2A%28%29%2B%3D__%7D',
|
||||
}
|
||||
),
|
||||
|
||||
'äöü escapeurl' => test_zci(
|
||||
"Percent-encoded URL: %E4%F6%FC",
|
||||
structured_answer => {
|
||||
input => ['äöü'],
|
||||
operation => 'URL percent-encode',
|
||||
result => '%E4%F6%FC',
|
||||
}
|
||||
),
|
||||
|
||||
|
|
Loading…
Reference in New Issue