1 #!/usr/local/bin/perl -w
8 # Test ability to escape() and unescape() punctuation characters
9 # except for qw(- . _).
10 ######################### We start with some black magic to print on failure.
11 use lib '../blib/lib','../blib/arch';
13 BEGIN {$| = 1; print "1..59\n"; }
14 END {print "not ok 1\n" unless $loaded;}
16 use CGI::Util qw(escape unescape);
20 ######################### End of black magic.
25 my($num, $true,$msg) = @_;
26 print($true ? "ok $num\n" : "not ok $num $msg\n");
29 # ASCII order, ASCII codepoints, ASCII repertoire
32 ' ' => '20', '!' => '21', '"' => '22', '#' => '23',
33 '$' => '24', '%' => '25', '&' => '26', '\'' => '27',
34 '(' => '28', ')' => '29', '*' => '2A', '+' => '2B',
35 ',' => '2C', '/' => '2F', # '-' => '2D', '.' => '2E'
36 ':' => '3A', ';' => '3B', '<' => '3C', '=' => '3D',
37 '>' => '3E', '?' => '3F', '[' => '5B', '\\' => '5C',
38 ']' => '5D', '^' => '5E', '`' => '60', # '_' => '5F',
39 '{' => '7B', '|' => '7C', '}' => '7D', '~' => '7E',
42 # The sort order may not be ASCII on EBCDIC machines:
46 foreach(sort(keys(%punct))) {
48 my $escape = "AbC\%$punct{$_}dEF";
49 my $cgi_escape = escape("AbC$_" . "dEF");
50 test($i, $escape eq $cgi_escape , "# $escape ne $cgi_escape");
52 my $unescape = "AbC$_" . "dEF";
53 my $cgi_unescape = unescape("AbC\%$punct{$_}dEF");
54 test($i, $unescape eq $cgi_unescape , "# $unescape ne $cgi_unescape");