summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlink <link@localhost>2001-02-21 08:56:32 +0000
committerlink <link@localhost>2001-02-21 08:56:32 +0000
commit0d8ea0eb2b620b0ab52500d3d52f7cd3d8acf787 (patch)
tree28c4dae936a9a64b8752b90882e3c292c808ace8
parent977f056bf54bce8cd4db3da88ce5d3122dbf62bf (diff)
downloadmarkup-validator-0d8ea0eb2b620b0ab52500d3d52f7cd3d8acf787.zip
markup-validator-0d8ea0eb2b620b0ab52500d3d52f7cd3d8acf787.tar.gz
markup-validator-0d8ea0eb2b620b0ab52500d3d52f7cd3d8acf787.tar.bz2
Use Text::Iconv for better error handling.
-rwxr-xr-xhttpd/cgi-bin/check55
1 files changed, 44 insertions, 11 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check
index eca50c5..6ea3f9f 100755
--- a/httpd/cgi-bin/check
+++ b/httpd/cgi-bin/check
@@ -8,7 +8,7 @@
# This source code is available under the license at:
# http://www.w3.org/Consortium/Legal/copyright-software
#
-# $Id: check,v 1.77 2001-02-20 10:47:53 gerald Exp $
+# $Id: check,v 1.78 2001-02-21 08:56:32 link Exp $
#
# We need Perl 5.004.
@@ -22,6 +22,7 @@ use URI::Escape;
use CGI::Carp;
use CGI qw(:cgi -newstyle_urls -private_tempfiles);
use Text::Wrap;
+use Text::Iconv;
#############################################################################
@@ -61,7 +62,6 @@ my $temp = "/tmp/validate.$$"; # @@ Use POSIX/IO::File tmpfiles instead!
#
# Executables and binaries
my $sp = '/usr/local/bin/lq-nsgmls';
-my $iconv = '/usr/bin/iconv';
my $weblint = '/usr/bin/weblint';
#
@@ -74,9 +74,9 @@ my $element_ref = 'http://www.htmlhelp.com/reference/html40/';
#
# Strings
-$VERSION = q$Revision: 1.77 $;
+$VERSION = q$Revision: 1.78 $;
$VERSION =~ s/Revision: ([\d\.]+) /$1/;
-$DATE = q$Date: 2001-02-20 10:47:53 $;
+$DATE = q$Date: 2001-02-21 08:56:32 $;
$MAINTAINER = 'gerald@w3.org';
my $notice = ''; # "<p><strong>Note: This service will be ...</strong>";
@@ -304,14 +304,10 @@ if ($File->{HTTP_Charset}) {
#
-# Setup conversion filter and SP environment for the effective charset.
-my $codeconv = '';
+# Setup SP environment for the charset.
if ($File->{Charset} ne 'unknown' and $File->{Charset} ne 'us-ascii') {
$ENV{SP_CHARSET_FIXED} = 'YES';
$ENV{SP_ENCODING} = 'utf-8';
- if ($File->{Charset} ne 'utf-8') {
- $codeconv = "$iconv -f $File->{Charset} -t utf-8 |";
- }
}
#
@@ -377,7 +373,7 @@ if ($File->{Type} eq 'xhtml') {
$catalog = "-c $sgmlstuff/catalog";
}
-my $command = "$codeconv $sp -E0 $xmlflags $catalog $decl";
+my $command = "$sp -E0 $xmlflags $catalog $decl";
if ( $ENV{SERVER_PORT} eq "8000" ) { # running on the test server?
print " <li>nsgmls command line: <code>$command</code>\n";
@@ -387,7 +383,20 @@ open CHECKER, "|$command - >$temp.esis 2>$temp"
or die "open(|$command - >$temp.esis 2>$temp) returned: $!\n";
print CHECKER $doctype, "\n" if $guessed_doctype == 1;
-for (@{$File->{Content}}) {print CHECKER $_, "\n"}
+if ( $File->{Charset} eq 'utf-8'
+ or $File->{Charset} eq 'us-ascii'
+ or $File->{Charset} eq 'unknown') {
+ for (@{$File->{Content}}) {print CHECKER $_, "\n"};
+} else {
+ eval {my $c = Text::Iconv->new($File->{Charset}, 'utf-8')};
+ if (not $@) {
+ my $c = Text::Iconv->new($File->{Charset}, 'utf-8');
+ for (@{$File->{Content}}) {print CHECKER $c->convert("$_\n")};
+ } else {
+ &print_charset_error($@, $File->{Charset});
+ &clean_up_and_exit;
+ }
+}
close CHECKER;
open ERRORS, "<$temp" or die "open($temp) returned: $!\n";
@@ -1265,6 +1274,30 @@ EOF
}
+
+#
+# Complain about strange charsets.
+sub print_charset_error {
+ my $error = shift;
+ my $charset = shift;
+
+ print <<".EOF.";
+ <p>
+ A fatal error occured when attempting to transliterate the document charset.
+ Either we do not support this charset yet, or you have specified a non-existant
+ character set (typically a misspelling such as "iso8859-1" for "iso-8859-1").
+ </p>
+ <p>The detected charset was "$charset".</p>
+ <p>The error was "$error".</p>
+ <p>
+ If you believe the charset to be valid you can submit a request for that
+ character set (see the <a href="/feedback.html">feedback page</a> for
+ details) and we will look into supporting it in the future.
+ </p>
+.EOF.
+}
+
+
sub output_css_validator_blurb {
my $uri = shift;
$uri = ent($uri);