2014-06-13 06:59:01 -07:00
|
|
|
package DDG::Goodie::URLEncode;
|
|
|
|
# ABSTRACT: Displays the percent-encoded url.
|
|
|
|
|
|
|
|
use DDG::Goodie;
|
2015-12-26 07:26:12 -08:00
|
|
|
use URI::Escape::XS qw(uri_escape);
|
2014-06-13 06:59:01 -07:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2016-06-10 01:50:21 -07:00
|
|
|
triggers startend => 'url encode', 'encode url', 'urlencode', 'encodeurl', 'url escape', 'escape url', 'urlescape', 'escapeurl',
|
|
|
|
'uri encode', 'encode uri', 'uriencode', 'encodeuri', 'uri escape', 'escape uri', 'uriescape', 'escapeuri';
|
2014-06-24 19:29:03 -07:00
|
|
|
|
2014-06-23 22:12:47 -07:00
|
|
|
zci answer_type => 'encoded_url';
|
2014-09-27 06:42:57 -07:00
|
|
|
zci is_cached => 1;
|
2014-06-24 19:29:03 -07:00
|
|
|
|
2014-06-13 06:59:01 -07:00
|
|
|
handle remainder => sub {
|
2014-10-10 03:01:58 -07:00
|
|
|
my $in = $_;
|
|
|
|
|
|
|
|
return unless $in;
|
|
|
|
|
2015-12-26 10:33:10 -08:00
|
|
|
## URI::Escape::XS::uri_escape expects a byte string, so downgrade our string
|
|
|
|
## https://metacpan.org/pod/URI::Escape::XS#uri_escape
|
|
|
|
utf8::downgrade($in);
|
2014-06-23 22:12:47 -07:00
|
|
|
|
2015-12-26 05:47:53 -08:00
|
|
|
my $encoded_url = uri_escape($in);
|
2014-06-23 22:12:47 -07:00
|
|
|
|
|
|
|
my $text = "Percent-encoded URL: $encoded_url";
|
2015-12-27 00:49:40 -08:00
|
|
|
my $subtitle = "URL percent-encode: $in";
|
|
|
|
|
|
|
|
return $text, structured_answer => {
|
|
|
|
data => {
|
2016-04-06 18:14:54 -07:00
|
|
|
title => html_enc($encoded_url),
|
|
|
|
subtitle => html_enc($subtitle)
|
2015-12-27 00:49:40 -08:00
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text',
|
|
|
|
moreAt => 0
|
|
|
|
}
|
|
|
|
};
|
2014-06-13 06:59:01 -07:00
|
|
|
};
|
2014-06-23 22:12:47 -07:00
|
|
|
|
2014-06-13 06:59:01 -07:00
|
|
|
1;
|