validator/httpd/cgi-bin check,1.712,1.713

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

Modified Files:
	check 
Log Message:
Code cleanups.

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.712
retrieving revision 1.713
diff -u -d -r1.712 -r1.713
--- check	10 Oct 2009 07:49:03 -0000	1.712
+++ check	23 Oct 2009 19:09:44 -0000	1.713
@@ -500,20 +500,20 @@
 
 # Always transcode, even if the content claims to be UTF-8
 $File = transcode($File);
-if (($File->{ContentType} eq "text/html") and ($File->{Charset}->{Default}) and $File->{'Error Flagged'}) {
-    $File->{'Error Flagged'} = FALSE; # reset
-    # we try again, this time with win-1252
-    $File->{Charset}->{Use} = 'windows-1252';
-    &add_warning('W04', {W04_charset => "windows-1252", W04_also_tried=> "UTF-8"});
-    $File = transcode($File);
-}
-if (($File->{ContentType} eq "text/html") and ($File->{Charset}->{Default}) and $File->{'Error Flagged'}) {
+
+# Try guessing if it didn't work out
+if ($File->{ContentType} eq 'text/html' && $File->{Charset}->{Default}) {
+  my $also_tried = 'UTF-8';
+  for my $cs (qw(windows-1252 iso-8859-1)) {
+    last unless $File->{'Error Flagged'};
     $File->{'Error Flagged'} = FALSE; # reset
-    # we try again, this time with latin1...
-    $File->{Charset}->{Use} = 'iso-8859-1';
-    &add_warning('W04', {W04_charset => "iso-8859-1", W04_also_tried => "UTF-8, windows-1252"});
+    $File->{Charset}->{Use} = $cs;
+    &add_warning('W04', { W04_charset => $cs, W04_also_tried => $also_tried });
     $File = transcode($File);
+    $also_tried .= ", $cs";
+  }
 }
+
 # if it still does not work, we abandon hope here
 &abort_if_error_flagged($File, O_CHARSET);
 
@@ -2714,7 +2714,7 @@
   # Transcoding failed
   if ($@) {
     my $line_num = 0;
-    foreach my $input_line (split /\r\n|\n|\r/, $input){
+    foreach my $input_line (split /\r\n|\n|\r/, $input) {
       $line_num++;
       eval { Encode::decode($cs, $input_line, Encode::FB_CROAK); };
       if ($@) {

Received on Friday, 23 October 2009 19:09:48 UTC