perl-unicode

Re: uri_escape and UTF-8 flag

2003-04-10 23:30:04
On Friday, April 11, 2003, at 08:38  AM, Lincoln Stein wrote:
Hi Dan,

I don't understand this stuff, but send me a patch file and I will incorporate
it, since I trust you to get it right.

Thank you for giving me such credibility. Patch follow right after my signature. In addition to the patch to CGI/Util.pm, I have added t/util-58.t which tests that.

Before the Patch
% make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/apache......ok
t/carp........ok
t/cookie......ok
t/fast........ok
        7/7 skipped: FCGI not installed, cannot continue
t/form........ok
t/function....ok
t/html........ok
t/pretty......ok
t/push........ok
        1/12 skipped: various reasons
t/request.....ok
t/switch......ok
t/util-58.....NOK 2#     Failed test (t/util-58.t at line 14)
#          got: '%5C0F%98FC%20%5F3E.txt'
#     expected: '%E5%B0%8F%E9%A3%BC%20%E5%BC%BE.txt'
# Looks like you failed 1 tests of 2.
t/util-58.....dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 2
        Failed 1/2 tests, 50.00% okay
t/util........ok
Failed Test Stat Wstat Total Fail  Failed  List of Failed
----------------------------------------------------------------------- --------
t/util-58.t    1   256     2    1  50.00%  2
8 subtests skipped.
Failed 1/13 test scripts, 92.31% okay. 1/335 subtests failed, 99.70% okay.
make: *** [test_dynamic] Error 2

After the Patch
% make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/apache......ok
t/carp........ok
t/cookie......ok
t/fast........ok
        7/7 skipped: FCGI not installed, cannot continue
t/form........ok
t/function....ok
t/html........ok
t/pretty......ok
t/push........ok
        1/12 skipped: various reasons
t/request.....ok
t/switch......ok
t/util-58.....ok
t/util........ok
All tests successful, 8 subtests skipped.
Files=13, Tests=335, 5 wallclock secs ( 2.44 cusr + 0.71 csys = 3.15 CPU)

After the Patch on Perl 5.6.0 (to make sure the patch is backward compatible)
n% make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/System/Library/Perl/darwin -I/System/Library/Perl -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
t/apache............ok
t/carp..............ok
t/cookie............ok
t/fast..............ok, 7/7 skipped: FCGI not installed, cannot continue
t/form..............ok
t/function..........ok
t/html..............ok
t/pretty............ok
t/push..............ok, 1/12 skipped: do_sleep() test may take a while
t/request...........ok
t/switch............ok
t/util-58...........skipped test on this platform
t/util..............ok
All tests successful, 1 test and 8 subtests skipped.
Files=13, Tests=333, 4 wallclock secs ( 1.54 cusr + 0.46 csys = 2.00 CPU)

BTW, thank you for CGI.pm. I recently published a book (in Japanese, in Japan) on perl and CGI and I evangelized the use of it a lot -- such a pity there are still so many using cgi-lib.pl (not to say it is bad but we are already in the 8th year since perl 5!) and there are still as many users reinventing the wheel just because they don't know of CGI.pm

Lincoln

Dan the Very Frequent User of CGI.pm

% diff -ruN CGI.pm-2.88 CGI.pm-2.88.dan
diff -ruN CGI.pm-2.88/CGI/Util.pm CGI.pm-2.88.dan/CGI/Util.pm
--- CGI.pm-2.88/CGI/Util.pm     Mon Dec 10 06:37:06 2001
+++ CGI.pm-2.88.dan/CGI/Util.pm Fri Apr 11 14:36:42 2003
@@ -199,6 +199,8 @@
shift() if @_ > 1 and ( ref($_[0]) || (defined $_[1] && $_[0] eq $CGI::DefaultClass));
   my $toencode = shift;
   return undef unless defined($toencode);
+  # force bytes while preserving backward compatibility -- dankogai
+  $toencode = pack("C*", unpack("C*", $toencode));
     if ($EBCDIC) {
$toencode=~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",$E2A[ord($1)])/eg;
     } else {
diff -ruN CGI.pm-2.88/MANIFEST CGI.pm-2.88.dan/MANIFEST
--- CGI.pm-2.88/MANIFEST        Mon Dec 10 06:37:06 2001
+++ CGI.pm-2.88.dan/MANIFEST    Fri Apr 11 14:39:44 2003
@@ -50,3 +50,4 @@
 t/request.t
 t/switch.t
 t/util.t
+t/util-58.t
diff -ruN CGI.pm-2.88/t/util-58.t CGI.pm-2.88.dan/t/util-58.t
--- CGI.pm-2.88/t/util-58.t     Thu Jan  1 09:00:00 1970
+++ CGI.pm-2.88.dan/t/util-58.t Fri Apr 11 14:46:45 2003
@@ -0,0 +1,16 @@
+#
+# This tests CGI::Util::escape() when fed with UTF-8-flagged string
+# -- dankogai
+BEGIN {
+    if ($] < 5.008) {
+       print "1..0 # \$] == $] < 5.008\n";
+       exit(0);
+    }
+}
+
+use Test::More tests => 2;
+use_ok("CGI::Util");
+my $uri = "\x{5c0f}\x{98fc} \x{5f3e}.txt"; # KOGAI, Dan, in Kanji
+is(CGI::Util::escape($uri), "%E5%B0%8F%E9%A3%BC%20%E5%BC%BE.txt",
+   "# Escape string with UTF-8 flag");
+__END__


<Prev in Thread] Current Thread [Next in Thread>