More foolproof handling of: &CGI::charset
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index dcd40ea..3d24a95 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -96,7 +96,7 @@ BEGIN
 }
 
 use WebConfig; # see also below: Wuse 'WebConfig';
-require CGI;   # for &escapeHTML
+require CGI;
 require Image::Size;   # for &imgsize
 use File::Basename;    # &basename
 use Carp qw(cluck confess);
@@ -232,6 +232,10 @@ my($class,%args)=@_;
 }
 
 # Although we have &tie-d *STDOUT we try to not to be dependent on it in My::Web itself.
+# Do not: Wprint $W->{"heading"},"undef"=>1;
+# as we would need to undef() it to turn it off and it would get defaulted in such case.
+# Do not: exists $W->{"heading"}
+# as we use a lot of 'for $W->{"heading"}' which instantiates it with the value: undef()
 sub Wprint($%)
 {
 my($text,%args)=@_;
@@ -249,6 +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(); };
+       # 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);
 }
 
@@ -416,7 +423,7 @@ sub footer (;$)
 
        Wprint vskip if $W->{"footer_delimit"};
 
-       Wprint $W->{"footing_delimit"},"undef"=>1;
+       do { Wprint $_ if $_; } for $W->{"footing_delimit"};
 
        Wprint "<hr />\n" if $W->{"footer"};
 
@@ -467,7 +474,7 @@ sub footer (;$)
                Wprint '<!-- '.$package.' - $'.$cvs_id.'$ -->'."\n" if $cvs_id;
                }
 
-       Wprint $W->{"footing"},"undef"=>1;
+       do { Wprint $_ if $_; } for $W->{"footing"};
 
        Wprint "</body></html>\n";
        exit 0;
@@ -865,7 +872,7 @@ HERE
        Wprint $W->{"body_attr"};
        Wprint ">\n";
 
-       Wprint $W->{"heading"},"undef"=>1;
+       do { Wprint $_ if $_; } for $W->{"heading"};
 }
 
 BEGIN {