2014-09-07 12:49:55 -07:00
#!/usr/bin/env perl
use strict ;
use warnings ;
2015-12-26 05:47:53 -08:00
use utf8 ;
2014-09-07 12:49:55 -07:00
use Test::More ;
2016-05-16 06:07:57 -07:00
use Test::Deep ;
2016-04-06 18:14:54 -07:00
use HTML::Entities ;
2014-09-07 12:49:55 -07:00
use DDG::Test::Goodie ;
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
2015-12-27 00:49:40 -08:00
sub build_answer {
my ( $ answer , $ sub ) = @ _ ;
$ sub = '' unless $ sub ;
return sprintf ( "URL Decoded: %s" , $ answer ) , structured_answer = > {
data = > {
2016-08-24 12:32:36 -07:00
title = > $ answer ,
subtitle = > "URL decode: $sub"
2015-12-27 00:49:40 -08:00
} ,
templates = > {
group = > 'text' ,
moreAt = > 0
}
}
}
2014-09-07 12:49:55 -07:00
ddg_goodie_test (
[ qw( DDG::Goodie::URLDecode ) ] ,
# Primary example queries
2015-12-27 00:49:40 -08:00
'url decode https%3A%2F%2Fduckduckgo.com%2F' = > test_zci ( build_answer ( 'https://duckduckgo.com/' , 'https%3A%2F%2Fduckduckgo.com%2F' ) ) ,
'decode url xkcd.com%2Fblag' = > test_zci ( build_answer ( 'xkcd.com/blag' , 'xkcd.com%2Fblag' ) ) ,
2014-09-07 12:49:55 -07:00
# Secondary example queries
2015-12-27 00:49:40 -08:00
'http%3A%2F%2Farstechnica.com%2F url unescape' = > test_zci ( build_answer ( 'http://arstechnica.com/' , 'http%3A%2F%2Farstechnica.com%2F' ) ) ,
'linux.com%2Ftour%2F unescape url' = > test_zci ( build_answer ( 'linux.com/tour/' , 'linux.com%2Ftour%2F' ) ) ,
'urldecode www.xkcd.com%2Fa-webcomic-of-romance%2Bmath%2Bsarcasm%2Blanguage' = > test_zci ( build_answer ( 'www.xkcd.com/a-webcomic-of-romance+math+sarcasm+language' , 'www.xkcd.com%2Fa-webcomic-of-romance%2Bmath%2Bsarcasm%2Blanguage' ) ) ,
'unescapeurl https%3A%2F%2Fexample.com%2Fzero%23clickinfo%5E%3Cgoodies%3E%3Bspice%3Afathead-%5C' = > test_zci ( build_answer ( 'https://example.com/zero#clickinfo^<goodies>;spice:fathead-\\' , 'https%3A%2F%2Fexample.com%2Fzero%23clickinfo%5E%3Cgoodies%3E%3Bspice%3Afathead-%5C' ) ) ,
'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 ( build_answer ( 'https://example.org/the answer to "[life], (the universe) .and. <everything>"' , 'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22' ) ) ,
'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22' = > test_zci ( build_answer ( 'https://example.org/the answer to "[life], (the universe) .and. <everything>"' , 'https%3A%2F%2Fexample.org%2Fthe%20answer%20to%20%22%5Blife%5D%2C%20(the%20universe)%20.and.%20%3Ceverything%3E%22' ) ) ,
'www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D unescapeurl' = > test_zci ( build_answer ( 'www.heroku.com/{rawwr!@#$%^&*()+=__}' , 'www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D' ) ) ,
'urldecode %3Cscript%3Ealert(1)%3C%2Fscript%3E' = > test_zci ( build_answer ( '<script>alert(1)</script>' , '%3Cscript%3Ealert(1)%3C%2Fscript%3E' ) ) ,
'https%3A%2F%2Fduckduckgo.com%2F' = > test_zci ( build_answer ( 'https://duckduckgo.com/' , 'https%3A%2F%2Fduckduckgo.com%2F' ) ) ,
'%E4%F6%FC' = > test_zci ( build_answer ( 'äöü' , '%E4%F6%FC' ) ) ,
'%20' = > test_zci ( build_answer ( 'Space' , '%20' ) ) ,
2016-06-06 13:44:38 -07:00
'uridecode 1%2B1' = > test_zci ( build_answer ( '1+1' , '1%2B1' ) ) ,
'uri decode 127.0.0.1%3A80' = > test_zci ( build_answer ( '127.0.0.1:80' , '127.0.0.1%3A80' ) ) ,
2016-07-15 13:32:58 -07:00
'URL decode hello%20there' = > test_zci ( build_answer ( 'hello there' , 'hello%20there' ) ) ,
'URI Decode hello%20there' = > test_zci ( build_answer ( 'hello there' , 'hello%20there' ) ) ,
2014-10-10 02:45:06 -07:00
'hello there unescapeurl' = > undef ,
'38% of 100 GBP' = > undef ,
'url decode tool' = > undef ,
'url decode online' = > undef
2014-09-07 12:49:55 -07:00
) ;
2016-05-16 06:18:04 -07:00
done_testing ;