URLDecode: Adding new goodie to replace closed source version
parent
f101ef6ebf
commit
eede9244b0
|
@ -0,0 +1,38 @@
|
|||
package DDG::Goodie::URLDecode;
|
||||
# ABSTRACT: Displays the decoded URL for a percent coded uri
|
||||
|
||||
use DDG::Goodie;
|
||||
use URI::Escape::XS qw(decodeURIComponent);
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
triggers startend => 'url decode', 'decode url', 'urldecode', 'decodeurl', 'url unescape', 'unescape url', 'urlunescape', 'unescapeurl';
|
||||
|
||||
primary_example_queries 'url decode https%3A%2F%2Fduckduckgo.com%2F' , 'decode url xkcd.com%2Fblag';
|
||||
secondary_example_queries 'http%3A%2F%2Farstechnica.com%2F url unescape', 'linux.com%2Ftour%2F unescape url';
|
||||
|
||||
zci answer_type => 'decoded_url';
|
||||
|
||||
name 'URLDecode';
|
||||
description 'Displays the uri from a percent encoded url';
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/URLDecode.pm';
|
||||
category 'computing_tools';
|
||||
topics 'programming', 'web_design';
|
||||
|
||||
|
||||
my $css = share("style.css")->slurp();
|
||||
sub append_css {
|
||||
my $html = shift;
|
||||
return "<style type='text/css'>$css</style>\n" . $html;
|
||||
};
|
||||
|
||||
handle remainder => sub {
|
||||
my $decoded_url = decodeURIComponent($_);
|
||||
|
||||
my $text = "URL: $decoded_url";
|
||||
my $html = '<div class="zci--urldecode"><span class="text--secondary">URL: </span><span class="text--primary">'.html_enc($decoded_url).'</span></div>';
|
||||
|
||||
return $text, html => append_css($html);
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,7 @@
|
|||
.zci--answer .zci--urldecode {
|
||||
padding-top: 0.25em;
|
||||
padding-bottom: 0.25em;
|
||||
font-weight: 300;
|
||||
font-size: 1.5em;
|
||||
word-wrap: break-word;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => 'decoded_url';
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(DDG::Goodie::URLDecode)],
|
||||
|
||||
# Primary example queries
|
||||
'url decode https%3A%2F%2Fduckduckgo.com%2F' => test_zci(
|
||||
"URL: https://duckduckgo.com/",
|
||||
html => qr#https://duckduckgo\.com/#
|
||||
),
|
||||
'decode url xkcd.com%2Fblag' => test_zci(
|
||||
"URL: xkcd.com/blag",
|
||||
html => qr#xkcd\.com/blag#
|
||||
),
|
||||
# Secondary example queries
|
||||
'http%3A%2F%2Farstechnica.com%2F url unescape' => test_zci(
|
||||
"URL: http://arstechnica.com/",
|
||||
html => qr#http://arstechnica\.com/#
|
||||
),
|
||||
'linux.com%2Ftour%2F unescape url' => test_zci(
|
||||
"URL: linux.com/tour/",
|
||||
html => qr#linux.com/tour/#
|
||||
),
|
||||
'urldecode www.xkcd.com%2Fa-webcomic-of-romance%2Bmath%2Bsarcasm%2Blanguage' => test_zci(
|
||||
"URL: www.xkcd.com/a-webcomic-of-romance+math+sarcasm+language",
|
||||
html => qr#www\.xkcd\.com/a-webcomic-of-romance\+math\+sarcasm\+language#
|
||||
),
|
||||
'unescapeurl https%3A%2F%2Fexample.com%2Fzero%23clickinfo%5E%3Cgoodies%3E%3Bspice%3Afathead-%5C' => test_zci(
|
||||
'URL: https://example.com/zero#clickinfo^<goodies>;spice:fathead-\\',
|
||||
html => qr|https://example.com/zero#clickinfo\^\<goodies\>;spice:fathead-\\|
|
||||
),
|
||||
'urlunescape https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22' => test_zci(
|
||||
qq`URL: https://example.org/the answer to "[life], (the universe) .and. <everything>"`,
|
||||
html => qr#https://example\.org/the answer to "\[life\], \(the universe\) \.and\. <everything>"#
|
||||
),
|
||||
'www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D unescapeurl' => test_zci(
|
||||
'URL: www.heroku.com/{rawwr!@#$%^&*()+=__}',
|
||||
html => qr|www\.heroku\.com/\{rawwr!@#\$%\^&\*\(\)\+=__\}|
|
||||
),
|
||||
'hello there unescapeurl' => test_zci(
|
||||
"URL: hello there",
|
||||
html => qr#hello there#
|
||||
),
|
||||
'urldecode %3Cscript%3Ealert(1)%3C%2Fscript%3E' => test_zci(
|
||||
"URL: <script>alert(1)</script>",
|
||||
html => qr|<script>alert\(1\)</script>|
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue