More foolproof handling of: &CGI::charset
authorshort <>
Sat, 10 Sep 2005 07:41:28 +0000 (07:41 +0000)
committershort <>
Sat, 10 Sep 2005 07:41:28 +0000 (07:41 +0000)
Web.pm

diff --git a/Web.pm b/Web.pm
index 872224e..3d24a95 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -96,8 +96,7 @@ BEGIN
 }
 
 use WebConfig; # see also below: Wuse 'WebConfig';
-require CGI;   # for &escapeHTML
-CGI::charset("utf-8"); # Prevent &CGI::escapeHTML breaking utf-8 like \xC4\x9B eq \x{11B}
+require CGI;
 require Image::Size;   # for &imgsize
 use File::Basename;    # &basename
 use Carp qw(cluck confess);
@@ -254,7 +253,9 @@ my($text)=@_;
        # Use &eval to prevent: Global $r object is not available. Set:\n\tPerlOptions +GlobalRequest\nin ...
        # CGI requires valid "r": check it beforehand here.
        confess "Calling dynamic URL generator from a static code" if !eval { Apache2::RequestUtil->request(); };
-       # See also somewhere else: CGI::charset("utf-8");
+       # Prevent &CGI::escapeHTML breaking utf-8 strings like: \xC4\x9B eq \x{11B}
+       do { cluck "charset==$_" if $_ && $_ ne "utf-8"; } for CGI::charset();
+       CGI::charset("utf-8");
        return CGI::escapeHTML($text);
 }