1 # test CGI::Util::escape
2 use Test::More tests => 4;
5 # Byte strings should be escaped byte by byte:
6 # 1) not a valid utf-8 sequence:
7 my $uri = "pe\x{f8}\x{ed}\x{e8}ko.ogg";
8 is(CGI::Util::escape($uri), "pe%F8%ED%E8ko.ogg", "Escape a Latin-2 string");
10 # 2) is a valid utf-8 sequence, but not an UTF-8-flagged string
11 # This happens often: people write utf-8 strings to source, but forget
12 # to tell perl about it by "use utf8;"--this is obviously wrong, but we
13 # have to handle it gracefully, for compatibility with GCI.pm under
16 $uri = "pe\x{c5}\x{99}\x{c3}\x{ad}\x{c4}\x{8d}ko.ogg";
17 is(CGI::Util::escape($uri), "pe%C5%99%C3%AD%C4%8Dko.ogg",
18 "Escape an utf-8 byte string");
22 # This tests CGI::Util::escape() when fed with UTF-8-flagged string
24 skip("Unicode strings not available in $]", 1) if ($] < 5.008);
25 $uri = "\x{5c0f}\x{98fc} \x{5f3e}.txt"; # KOGAI, Dan, in Kanji
26 is(CGI::Util::escape($uri), "%E5%B0%8F%E9%A3%BC%20%E5%BC%BE.txt",
27 "Escape string with UTF-8 flag");