diff options
author | ville <ville@localhost> | 2009-10-23 19:09:44 +0000 |
---|---|---|
committer | ville <ville@localhost> | 2009-10-23 19:09:44 +0000 |
commit | 0ea874816329e50e90151cc2e7c7df426b163ea9 (patch) | |
tree | 800e199894716d1a29353b2703ddfbec52679a1e | |
parent | 470f3dd409707361ee04c8a8aaf5dc3b4364054f (diff) | |
download | markup-validator-0ea874816329e50e90151cc2e7c7df426b163ea9.zip markup-validator-0ea874816329e50e90151cc2e7c7df426b163ea9.tar.gz markup-validator-0ea874816329e50e90151cc2e7c7df426b163ea9.tar.bz2 |
Code cleanups.
-rwxr-xr-x | httpd/cgi-bin/check | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check index 8a0b17c..e330c08 100755 --- a/httpd/cgi-bin/check +++ b/httpd/cgi-bin/check @@ -14,7 +14,7 @@ # This source code is available under the license at: # http://www.w3.org/Consortium/Legal/copyright-software # -# $Id: check,v 1.712 2009-10-10 07:49:03 ville Exp $ +# $Id: check,v 1.713 2009-10-23 19:09:44 ville Exp $ # # Disable buffering on STDOUT! $| = 1; @@ -208,7 +208,7 @@ Directory not readable (permission denied): @_r # # Strings - $VERSION = q$Revision: 1.712 $; + $VERSION = q$Revision: 1.713 $; $VERSION =~ s/Revision: ([\d\.]+) /$1/; # @@ -500,20 +500,20 @@ unless ($File->{Charset}->{Use}) { # No charset given... # 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 @@ sub transcode { # 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 ($@) { |