summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorot <ot@localhost>2007-09-07 07:32:54 +0000
committerot <ot@localhost>2007-09-07 07:32:54 +0000
commitc6349f78e0da7ebec89f44b76b65f42435e7c6e4 (patch)
tree2d0760ed6548a20d1dcf22817b8ce10c448ad99b
parentc9e26c48ec9c883bc37c6eb8a7b56a17f4e35ce8 (diff)
downloadmarkup-validator-c6349f78e0da7ebec89f44b76b65f42435e7c6e4.zip
markup-validator-c6349f78e0da7ebec89f44b76b65f42435e7c6e4.tar.gz
markup-validator-c6349f78e0da7ebec89f44b76b65f42435e7c6e4.tar.bz2
applying karl's idea that the doctype declaration
we sneak in should not be at the beginning of the doc, but rather, just before the root element. This should fix http://www.w3.org/Bugs/Public/show_bug.cgi?id=857
-rwxr-xr-xhttpd/cgi-bin/check27
1 files changed, 23 insertions, 4 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check
index 4338d6b..0cad1ee 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.561 2007-09-05 08:20:23 ot Exp $
+# $Id: check,v 1.562 2007-09-07 07:32:54 ot Exp $
#
# Disable buffering on STDOUT!
@@ -186,7 +186,7 @@ Directory not readable (permission denied): @_r
#
# Strings
- $VERSION = q$Revision: 1.561 $;
+ $VERSION = q$Revision: 1.562 $;
$VERSION =~ s/Revision: ([\d\.]+) /$1/;
#
@@ -1538,6 +1538,7 @@ sub override_doctype {
local $org_dtd = '';
local $HTML = '';
local $seen = FALSE;
+ local $seen_root = FALSE;
my $declaration = sub {
$seen = TRUE;
@@ -1551,9 +1552,28 @@ sub override_doctype {
$org_dtd = &ent($_[0]);
}
};
+
+ my $start_element = sub{
+ if ($seen_root) {
+ $HTML .= $_[0]; # Stash it as is... moving on
+ }
+ else {
+ $seen_root = TRUE;
+ if ($seen) {
+ # doctype addition aldready done, we move on
+ $HTML .= $_[0];
+ }
+ else {
+ # no original doctype present, hence none replaced already
+ # => we sneak the chosen doctype before the root elt
+ $HTML .= "$dtd\n" . $_[0];
+ }
+ }
+ };
HTML::Parser->new(default_h => [sub {$HTML .= shift}, 'text'],
- declaration_h => [$declaration, 'text']
+ declaration_h => [$declaration, 'text'],
+ start_h => [$start_element, "text"]
)->parse(join "\n", @{$File->{Content}})->eof();
$File->{Content} = [split /\n/, $HTML];
@@ -1567,7 +1587,6 @@ sub override_doctype {
$File->{Tentative} |= T_ERROR; # Tag it as Invalid.
}
} else {
- unshift @{$File->{Content}}, $dtd;
if ($File->{Opt}->{FB}->{DOCTYPE}) {
&add_warning('W16', {W16_dtd => $File->{Opt}->{DOCTYPE}});