validator/httpd/cgi-bin check,1.775,1.776

Update of /sources/public/validator/httpd/cgi-bin
In directory hutz:/tmp/cvs-serv15868/httpd/cgi-bin

Modified Files:
	check 
Log Message:
Avoid malformed comments when overriding doctype or charset.

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.775
retrieving revision 1.776
diff -u -d -r1.775 -r1.776
--- check	7 May 2010 17:22:58 -0000	1.775
+++ check	7 May 2010 17:41:29 -0000	1.776
@@ -1892,6 +1892,16 @@
 }
 
 #
+# Escape text to be included in markup comment.
+sub escape_comment
+{
+    local $_ = shift;
+    return '' unless defined;
+    s/--/- /g;
+    return $_;
+}
+
+#
 # Return $_[0] encoded for HTML entities (cribbed from merlyn).
 #
 # Note that this is used both for HTML and XML escaping.
@@ -2008,7 +2018,7 @@
             $HTML .= $text;    # Stash it as is...
         }
         else {
-            $HTML .= "$dtd<!-- $text -->";
+            $HTML .= "$dtd<!-- " . &escape_comment($text) . " -->";
         }
     };
 
@@ -2088,14 +2098,16 @@
               (^<\?xml\b[^>]*?${ws}encoding${ws}*=${ws}*(["']))
               (${cs})
               (\3.*?\?>)
-          )/lc($4) eq lc($charset) ? "$1" : "$2$charset$5<!-- $1 -->"/esx;
+          )/lc($4) eq lc($charset) ?
+              "$1" : "$2$charset$5<!-- " . &escape_comment($1) ." -->"/esx;
 
     # <meta charset="charset">
     $content =~ s/(
               (<meta\b[^>]*?${ws}charset${ws}*=${ws}*["']?${ws}*)
               (${cs})
               (.*?>)
-          )/lc($3) eq lc($charset) ? "$1" : "$2$charset$4<!-- $1 -->"/esix;
+          )/lc($3) eq lc($charset) ?
+              "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix;
 
     # <meta http-equiv="content-type" content="some/type; charset=charset">
     $content =~ s/(
@@ -2104,7 +2116,8 @@
                   content${ws}*=${ws}*["']?[^"'>]+?;${ws}*charset${ws}*=${ws}*)
               (${cs})
               (.*?>)
-          )/lc($3) eq lc($charset) ? "$1" : "$2$charset$4<!-- $1 -->"/esix;
+          )/lc($3) eq lc($charset) ?
+              "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix;
 
     # <meta content="some/type; charset=charset" http-equiv="content-type">
     $content =~ s/(
@@ -2112,7 +2125,8 @@
                   content${ws}*=${ws}*["']?[^"'>]+?;${ws}*charset${ws}*=${ws}*)
               (${cs})
               ([^>]*?${ws}http-equiv${ws}*=${ws}*["']?${ws}*content-type\b.*?>)
-          )/lc($3) eq lc($charset) ? "$1" : "$2$charset$4<!-- $1 -->"/esix;
+          )/lc($3) eq lc($charset) ?
+              "$1" : "$2$charset$4<!-- " . &escape_comment($1) . " -->"/esix;
 
     $File->{Content} = [split /\n/, $content];
 }

Received on Friday, 7 May 2010 17:41:33 UTC