diff options
author | ot <ot@localhost> | 2007-05-07 19:17:58 +0000 |
---|---|---|
committer | ot <ot@localhost> | 2007-05-07 19:17:58 +0000 |
commit | 86eef21345edbca7f8ef532e91d2117c616f6934 (patch) | |
tree | 2576b8668203caf792ecc305b3774f34998e09cb | |
parent | ff8ed778f0a58b141cedc75bb802b2a42d1105d4 (diff) | |
download | markup-validator-86eef21345edbca7f8ef532e91d2117c616f6934.zip markup-validator-86eef21345edbca7f8ef532e91d2117c616f6934.tar.gz markup-validator-86eef21345edbca7f8ef532e91d2117c616f6934.tar.bz2 |
for documents served as XML, and for which the root element is not <html>,
the fallback to XHTML is not a great choice. Instead, we can perform a basic xml-wf checking,
and report a positive result for these.
-rwxr-xr-x | htdocs/dev/tests/xhtml1-missing-doctype-and-xmlns.xhtml | 1 | ||||
-rwxr-xr-x | httpd/cgi-bin/check | 45 | ||||
-rw-r--r-- | share/templates/en_US/table.tmpl | 9 | ||||
-rw-r--r-- | share/templates/en_US/valid.tmpl | 3 |
4 files changed, 42 insertions, 16 deletions
diff --git a/htdocs/dev/tests/xhtml1-missing-doctype-and-xmlns.xhtml b/htdocs/dev/tests/xhtml1-missing-doctype-and-xmlns.xhtml index 1381810..529cfe1 100755 --- a/htdocs/dev/tests/xhtml1-missing-doctype-and-xmlns.xhtml +++ b/htdocs/dev/tests/xhtml1-missing-doctype-and-xmlns.xhtml @@ -6,5 +6,6 @@ <p>This is a simple bogus HTML doc with neither a doctype nor an xmlns attribute on its root element. </p> +<img /> </body> </html> diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check index 67abc59..90b1d60 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.517 2007-05-07 16:14:15 ot Exp $ +# $Id: check,v 1.518 2007-05-07 19:17:58 ot Exp $ # # Disable buffering on STDOUT! @@ -180,7 +180,7 @@ Directory not readable (permission denied): @_r # # Strings - $VERSION = q$Revision: 1.517 $; + $VERSION = q$Revision: 1.518 $; $VERSION =~ s/Revision: ([\d\.]+) /$1/; # @@ -254,6 +254,8 @@ $File->{Charset}->{Override} = ''; # From CGI/user override. # Misc simple types. $File->{Mode} = 'SGML'; # Default parse mode is SGML. +# By default, perform validation (we may perform only xml-wf in some cases) +$File->{XMLWF_ONLY} = FALSE; # # Listrefs. $File->{Warnings} = []; # Warnings... @@ -588,8 +590,7 @@ if ($File->{Charset}->{Use} eq 'utf-8' && # # Override DOCTYPE if user asked for it. if ($File->{Opt}->{DOCTYPE} - and not $File->{Opt}->{DOCTYPE} =~ /(Inline|detect)/i - and $File->{Opt}->{DOCTYPE} ne '1' ) { + and not $File->{Opt}->{DOCTYPE} =~ /(Inline|detect)/i) { $File = &override_doctype($File); } @@ -781,7 +782,7 @@ sub parse (\$) { # # Force "XML" if type is an XML type and an FPI was not found. # Otherwise set the type to be the FPI. -if (&is_xml($File) and not $File->{DOCTYPE}) { +if (&is_xml($File) and not $File->{DOCTYPE} and lc($File->{Root}) ne 'html') { $File->{Version} = 'XML'; } else { $File->{Version} = $File->{DOCTYPE} unless $File->{Version}; @@ -962,7 +963,9 @@ sub prep_template ($$) { $T->param(tip_uri => $tip->[0]); $T->param(tip_slug => $tip->[1]); - # + # Root Element + $T->param(root_element => $File->{Root}); + # Namespaces... $T->param(file_namespace => $File->{Namespace}); my %seen_ns = (); @@ -1102,7 +1105,9 @@ sub report_valid { if ($File->{Opt}->{'Outline'}) { $T->param(file_outline => $File->{heading_outline}); } - + if ($File->{XMLWF_ONLY}){ + $T->param(xmlwf_only => TRUE); + } my $thispage = self_url_file($File); $T->param(file_thispage => $thispage); } @@ -2358,9 +2363,17 @@ sub W3C::Validator::SAXHandler::error } } + if ($err->{num} eq '187') + # filtering out no "document type declaration; will parse without validation" + # if root element is not html and mode is xml... + { + # since parsing was done without validation, result can only be "well-formed" + if ($File->{Mode} eq 'XML' and lc($File->{Root}) ne 'html') { + $File->{XMLWF_ONLY} = TRUE; + } + return; + } - # ... - $File->{'Is Valid'} = FALSE if $err->{type} eq 'E'; # Workaround for onsgmls as of 1.5 sometimes allegedly reporting errors # beyond EOL. If you see this warning in your web server logs, please @@ -2379,12 +2392,14 @@ sub W3C::Validator::SAXHandler::error $File->{Templates}->{Error}->param(fatal_parse_extid_msg => $err->{msg}); } - # No DOCTYPE. + # No DOCTYPE found! We are falling back to vanilla DTD if ($err->{msg} =~ m(prolog can\'t be omitted)) { - my $dtd = ($File->{Mode} eq 'XML' ? - 'XHTML 1.0 Transitional' : 'HTML 4.01 Transitional' ); - - add_warning('W09', {W09_dtd => $dtd}); + if (lc($File->{Root}) eq 'html') { + my $dtd = ($File->{Mode} eq 'XML' ? + 'XHTML 1.0 Transitional' : 'HTML 4.01 Transitional' ); + add_warning('W09', {W09_dtd => $dtd}); + } + return; # Don't report this as a normal error. } @@ -2392,6 +2407,8 @@ sub W3C::Validator::SAXHandler::error abort_if_error_flagged($File, O_DOCTYPE); push @{$File->{Errors}}, $err; + # ... + $File->{'Is Valid'} = FALSE if $err->{type} eq 'E'; if (defined $mess->{aux_message}) { diff --git a/share/templates/en_US/table.tmpl b/share/templates/en_US/table.tmpl index 2f92125..c581233 100644 --- a/share/templates/en_US/table.tmpl +++ b/share/templates/en_US/table.tmpl @@ -3,7 +3,8 @@ <h2 class="tentative_valid">This Page Is <em>Tentatively</em> Valid <TMPL_VAR NAME="file_version" ESCAPE="HTML"></h2> <TMPL_ELSE> - <h2 class="valid">This Page Is Valid <TMPL_VAR NAME="file_version" ESCAPE="HTML">!</h2> + <h2 class="valid">This Page Is <TMPL_IF NAME="xmlwf_only">well-formed<TMPL_ELSE>Valid</TMPL_IF> + <TMPL_VAR NAME="file_version" ESCAPE="HTML">!</h2> </TMPL_IF> <TMPL_ELSE> <TMPL_IF NAME="fatal_error"> @@ -73,6 +74,12 @@ <tr><th>Doctype:</th><td colspan="2"><TMPL_INCLUDE NAME="popup_doctype.tmpl"></td></tr> </TMPL_IF> </TMPL_IF> +<TMPL_IF NAME="root_element"> + <tr> + <th>Root Element:</th> + <td colspan="2"><TMPL_VAR NAME="root_element" ESCAPE="HTML"></td> + </tr> +</TMPL_IF> <TMPL_IF NAME="file_namespace"> <tr> <th>Root Namespace:</th> diff --git a/share/templates/en_US/valid.tmpl b/share/templates/en_US/valid.tmpl index f92c268..e683f49 100644 --- a/share/templates/en_US/valid.tmpl +++ b/share/templates/en_US/valid.tmpl @@ -34,7 +34,8 @@ to match the changes we have performed automatically, but <strong>it will not be valid until you make these changes</strong>. <TMPL_ELSE> - was checked and found to be valid + was checked and found to be + <TMPL_IF NAME="xmlwf_only">well-formed<TMPL_ELSE>valid</TMPL_IF> <TMPL_VAR NAME="file_version" ESCAPE="HTML">. This means that the resource in question identified itself as "<TMPL_VAR NAME="file_version" ESCAPE="HTML">" and that we successfully |