From b074a6e247a4723fbd84d72445949813c8b7420b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 31 Jul 2011 14:55:17 +0200 Subject: [PATCH] UCW::CGI: Implemented UTF-8 mode (compatible with `use utf8') --- ucw/perl/UCW/CGI.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ucw/perl/UCW/CGI.pm b/ucw/perl/UCW/CGI.pm index f7e033d1..73238a5b 100644 --- a/ucw/perl/UCW/CGI.pm +++ b/ucw/perl/UCW/CGI.pm @@ -60,17 +60,23 @@ our @ISA = qw(Exporter); our @EXPORT = qw(&html_escape &url_escape &url_deescape &url_param_escape &url_param_deescape &self_ref &self_form &http_get); our @EXPORT_OK = qw(); +our $utf8_mode = 0; + ### Escaping ### sub url_escape($) { my $x = shift @_; + utf8::encode($x) if $utf8_mode; $x =~ s/([^-\$_.!*'(),0-9A-Za-z\x80-\xff])/"%".unpack('H2',$1)/ge; + utf8::decode($x) if $utf8_mode; return $x; } sub url_deescape($) { my $x = shift @_; + utf8::encode($x) if $utf8_mode; $x =~ s/%(..)/pack("H2",$1)/ge; + utf8::decode($x) if $utf8_mode; return $x; } @@ -138,6 +144,7 @@ sub parse_raw_args_ll($$) { my ($arg, $s) = @_; $s =~ s/\r\n/\n/g; $s =~ s/\r/\n/g; + utf8::decode($s) if $utf8_mode; push @{$raw_args{$arg}}, $s; } -- 2.39.2