2014-09-07 12:49:55 -07:00
|
|
|
package DDG::Goodie::URLDecode;
|
2014-09-10 14:49:31 -07:00
|
|
|
# ABSTRACT: Displays the decoded URL for a percent encoded uri
|
2014-09-07 12:49:55 -07:00
|
|
|
|
|
|
|
use DDG::Goodie;
|
|
|
|
use URI::Escape::XS qw(decodeURIComponent);
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2014-09-10 14:49:31 -07:00
|
|
|
my $trigger_words = qr#urlunescape|unescapeurl|(unescape url)|decodeurl|(decode url)|urldecode|(url decode)|(url unescape)#;
|
2014-09-07 12:49:55 -07:00
|
|
|
|
2014-09-11 12:16:14 -07:00
|
|
|
triggers query_raw => qr#%[0-9A-Fa-f]{2}#;
|
2014-09-10 14:49:31 -07:00
|
|
|
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';
|
2014-09-07 12:49:55 -07:00
|
|
|
|
2014-09-10 14:49:31 -07:00
|
|
|
zci answer_type => 'decoded_url';
|
2014-10-10 02:45:06 -07:00
|
|
|
zci is_cached => 1;
|
2014-09-07 12:49:55 -07:00
|
|
|
|
2014-09-10 14:49:31 -07:00
|
|
|
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';
|
2014-09-07 12:49:55 -07:00
|
|
|
|
2015-01-07 10:24:47 -08:00
|
|
|
attribution web => [ 'https://www.duckduckgo.com', 'DuckDuckGo' ],
|
|
|
|
github => [ 'duckduckgo', 'DuckDuckGo'],
|
|
|
|
twitter => ['duckduckgo', 'DuckDuckGo'];
|
|
|
|
|
2014-09-11 12:16:14 -07:00
|
|
|
handle query_raw => sub {
|
2014-10-07 09:38:19 -07:00
|
|
|
# unless trigger words exist, only answer when we have a single word
|
|
|
|
unless (m/$trigger_words/) {
|
|
|
|
return if m/\s+/;
|
|
|
|
}
|
2014-09-10 14:49:31 -07:00
|
|
|
#remove triggers and trim
|
2014-09-11 12:16:14 -07:00
|
|
|
s/(^$trigger_words)|($trigger_words$)//i;
|
2014-09-10 14:49:31 -07:00
|
|
|
s/(^\s+)|(\s+$)//;
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2014-10-10 02:45:06 -07:00
|
|
|
my $in = $_;
|
|
|
|
my $decoded = decodeURIComponent($in);
|
2014-09-18 12:15:14 -07:00
|
|
|
|
2014-10-10 02:45:06 -07:00
|
|
|
if ($decoded =~ /^\s+$/) {
|
2014-09-18 12:15:14 -07:00
|
|
|
$decoded =~ s/\r/CReturn/;
|
|
|
|
$decoded =~ s/\n/Newline/;
|
|
|
|
$decoded =~ s/\t/Tab/;
|
|
|
|
$decoded =~ s/\s/Space/;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $text = "URL Decoded: $decoded";
|
2014-09-07 12:49:55 -07:00
|
|
|
|
2014-10-10 02:45:06 -07:00
|
|
|
return $text,
|
|
|
|
structured_answer => {
|
|
|
|
input => [html_enc($in)],
|
|
|
|
operation => 'URL decode',
|
|
|
|
result => html_enc($decoded)
|
|
|
|
};
|
2014-09-07 12:49:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
1;
|