W3C home > Mailing lists > Public > www-validator-cvs@w3.org > June 2009

validator/httpd/cgi-bin check,1.657,1.658

From: Ville Skytta via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 23 Jun 2009 18:08:23 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MJAPv-0007vJ-6k@lionel-hutz.w3.org>
Update of /sources/public/validator/httpd/cgi-bin
In directory hutz:/tmp/cvs-serv30427/httpd/cgi-bin

Modified Files:
	check 
Log Message:
Improve Content-Encoding decode error handling.

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.657
retrieving revision 1.658
diff -u -d -r1.657 -r1.658
--- check	23 Jun 2009 17:59:48 -0000	1.657
+++ check	23 Jun 2009 18:08:21 -0000	1.658
@@ -915,7 +915,9 @@
     $File->{Templates}->{Error}->param(fatal_missing_checker  => "HTML5 Validator");
   }
   else {
-    my $content = $res->decoded_content(charset => 'none');
+    my $content = &get_content($File, $res);
+    return $File if $File->{'Error Flagged'};
+
     # and now we parse according to http://wiki.whatwg.org/wiki/Validator.nu_XML_Output
     # I wish we could use XML::LibXML::Reader here. but SHAME on those major
     # unix distributions still shipping with libxml2 2.6.16… 4 years after its release
@@ -1046,7 +1048,9 @@
     $File->{Templates}->{Error}->param(fatal_missing_checker  => "HTML5 Validator");
   }
   else {
-    my $content = $res->decoded_content(charset => 'none');
+    my $content = &get_content($File, $res);
+    return $File if $File->{'Error Flagged'};
+
     # and now we parse according to http://wiki.whatwg.org/wiki/Validator.nu_XML_Output
     # I wish we could use XML::LibXML::Reader here. but SHAME on those major
     # unix distributions still shipping with libxml2 2.6.16… 4 years after its release
@@ -1723,7 +1727,8 @@
                           scalar($res->request->uri),
                          );
 
-  my $content = $res->decoded_content(charset => 'none');
+  my $content = &get_content($File, $res);
+  return $File if $File->{'Error Flagged'};
 
   $File->{Bytes}           = $content;
   $File->{Mode}            = $mode;
@@ -1851,6 +1856,31 @@
 }
 
 #
+# Get content with Content-Encodings decoded from a response.
+sub get_content ($$) {
+  my $File = shift;
+  my $res  = shift;
+
+  my $content;
+  eval {
+    $content = $res->decoded_content(charset => 'none', raise_error => 1);
+  };
+  if ($@) {
+    (my $errmsg = $@) =~ s/ at .*//s;
+    my $cenc = $res->header("Content-Encoding");
+    my $uri  = $res->request->uri;
+    $File->{'Error Flagged'} = TRUE;
+    $File->{Templates}->{Error}->param(fatal_decode_error  => TRUE);
+    $File->{Templates}->{Error}->param(fatal_decode_errmsg => $errmsg);
+    $File->{Templates}->{Error}->param(fatal_decode_cenc   => $cenc);
+    # Include URI because it might be a subsystem (eg. HTML5 validator) one
+    $File->{Templates}->{Error}->param(fatal_decode_uri    => $uri);
+  }
+
+  return $content;
+}
+
+#
 # Check recursion level and enforce Max Recursion limit.
 sub check_recursion ($$) {
   my $File = shift;
Received on Tuesday, 23 June 2009 18:08:32 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:36 UTC