diff options
author | Ville Skytt? <ville.skytta@iki.fi> | 2010-07-04 11:31:14 +0300 |
---|---|---|
committer | Ville Skytt? <ville.skytta@iki.fi> | 2010-07-04 11:31:14 +0300 |
commit | cd0a62ff7cac837559b52b16d91fe274f9fd3274 (patch) | |
tree | acdec32f38a5de3cf9909f797e7a7acb0537f471 | |
parent | 033e83da1db1f86e2c0f6ba4aa5814cca9521aca (diff) | |
download | markup-validator-cd0a62ff7cac837559b52b16d91fe274f9fd3274.zip markup-validator-cd0a62ff7cac837559b52b16d91fe274f9fd3274.tar.gz markup-validator-cd0a62ff7cac837559b52b16d91fe274f9fd3274.tar.bz2 |
Improve error location info to include URI for non-doc resources.
http://www.w3.org/Bugs/Public/show_bug.cgi?id=9933
-rwxr-xr-x | htdocs/whatsnew.html | 6 | ||||
-rwxr-xr-x | httpd/cgi-bin/check | 35 | ||||
-rw-r--r-- | share/templates/en_US/error_loop.tmpl | 3 | ||||
-rw-r--r-- | share/templates/en_US/error_loop_grouped.tmpl | 5 |
4 files changed, 43 insertions, 6 deletions
diff --git a/htdocs/whatsnew.html b/htdocs/whatsnew.html index 3484979..a042186 100755 --- a/htdocs/whatsnew.html +++ b/htdocs/whatsnew.html @@ -43,6 +43,12 @@ <li> Enhancement: improved error output performance. </li> + <li> + Enhancement: error/warning location information now + <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=9933">makes + it clearer</a> whether the error occurred in the validated + document or an external resource related to it. + </li> </ul> </dd> diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check index 63e39c8..778dc88 100755 --- a/httpd/cgi-bin/check +++ b/httpd/cgi-bin/check @@ -1144,7 +1144,9 @@ sub html5_validate (\$) elsif ($attribute->name eq "last-line") { $err->{line} = $attribute->getValue(); } - + elsif ($attribute->name eq "url") { + $err->{uri} = $attribute->getValue(); + } } } my @child_nodes = $message_node->childNodes; @@ -1291,6 +1293,7 @@ sub xmlwf (\$) my $err_obj = $@; while ($err_obj) { my $err; + $err->{uri} = $err_obj->file(); $err->{src} = '...'; # do this with show_open_entities()? $err->{line} = $err_obj->line(); $err->{char} = $err_obj->column(); @@ -1391,6 +1394,7 @@ sub xmlwf (\$) # formatting the error message for output my $err; + # TODO: $err->{uri} (need test case) $err->{src} = '...'; # do this with show_open_entities()? $err->{line} = $xmlwf_error_line; $err->{char} = $xmlwf_error_col; @@ -2328,6 +2332,30 @@ sub report_errors ($) my $line; my $col = 0; + # We want errors in the doc that was validated to appear without + # $err->{uri}, and non-doc errors with it pointing to the external + # entity or the like where the error is. This usually works as + # long as we're passing docs to parsers as strings, but S::P::O + # (at least as of 0.994) seems to give us "3" as the FileName in + # those cases so we try to filter out everything that doesn't look + # like a useful URI. + if ($err->{uri}) { + if ($err->{uri} !~ m|/|) { + delete $err->{uri}; + } + else { + # Mask local file paths + my $uri = URI->new($err->{uri}); + if (!$uri->scheme() || $uri->scheme() eq 'file') { + $err->{uri_is_file} = TRUE; + $err->{uri} = ($uri->path_segments())[-1]; + } + else { + $err->{uri} = $uri->canonical(); + } + } + } + # avoid truncating lines that do not exist if (defined($err->{line}) && $File->{Content}->[$err->{line} - 1]) { @@ -3430,6 +3458,7 @@ sub start_element # but not present my $err; my $location = $self->{_parser}->get_location(); + $err->{uri} = $location->{FileName}; $err->{src} = '...'; # do this with show_open_entities()? $err->{line} = $location->{LineNumber}; $err->{char} = $location->{ColumnNumber}; @@ -3451,6 +3480,7 @@ sub start_element # whine if root xmlns element is not the one specificed by the spec my $err; my $location = $self->{_parser}->get_location(); + $err->{uri} = $location->{FileName}; $err->{src} = '...'; # do this with show_open_entities()? $err->{line} = $location->{LineNumber}; $err->{char} = $location->{ColumnNumber}; @@ -3479,10 +3509,9 @@ sub error } my $File = $self->{_file}; - # TODO: this does not filter out errors in DTDs. - my $err; + $err->{uri} = $self->{_parser}->get_location()->{FileName}; $err->{src} = '...'; # do this with show_open_entities()? $err->{line} = $mess->{primary_message}{LineNumber}; $err->{char} = $mess->{primary_message}{ColumnNumber} + 1; diff --git a/share/templates/en_US/error_loop.tmpl b/share/templates/en_US/error_loop.tmpl index 3cfb075..62e7018 100644 --- a/share/templates/en_US/error_loop.tmpl +++ b/share/templates/en_US/error_loop.tmpl @@ -2,7 +2,8 @@ <TMPL_LOOP NAME="file_errors"> <li<TMPL_IF NAME="class"> class="<TMPL_VAR NAME="class">"</TMPL_IF>> <span class="err_type"><TMPL_IF NAME="err_type_info"><img src="images/info_icons/info.png" alt="Info" title="Info" /></TMPL_IF><TMPL_IF NAME="err_type_warn"><img src="images/info_icons/warning.png" alt="Warning" title="Warning" /></TMPL_IF><TMPL_IF NAME="err_type_err"><img src="images/info_icons/error.png" alt="Error" title="Error" /></TMPL_IF></span> - <TMPL_IF NAME="line"><em>Line <TMPL_IF NAME="opt_show_source"><a href="#line-<TMPL_VAR NAME="line" ESCAPE="HTML">"></TMPL_IF><TMPL_VAR NAME="line" ESCAPE="HTML"><TMPL_IF NAME="opt_show_source"></a></TMPL_IF><TMPL_IF NAME="char">, + <TMPL_IF NAME="uri">(<TMPL_IF NAME="uri_is_file">Validator local file "<TMPL_VAR NAME="uri" ESCAPE="HTML">"<TMPL_ELSE><a href="<TMPL_VAR NAME="uri" ESCAPE="HTML">"><TMPL_VAR NAME="uri" ESCAPE="HTML"></a></TMPL_IF>)</TMPL_IF> + <TMPL_IF NAME="line"><em>Line <TMPL_IF NAME="opt_show_source"><TMPL_UNLESS NAME="uri"><a href="#line-<TMPL_VAR NAME="line" ESCAPE="HTML">"></TMPL_UNLESS></TMPL_IF><TMPL_VAR NAME="line" ESCAPE="HTML"><TMPL_IF NAME="opt_show_source"><TMPL_UNLESS NAME="uri"></a></TMPL_UNLESS></TMPL_IF><TMPL_IF NAME="char">, Column <TMPL_VAR NAME="char" ESCAPE="HTML"></TMPL_IF></em>:</TMPL_IF> <span class="msg"><TMPL_VAR NAME="msg" ESCAPE="HTML"></span> <TMPL_IF NAME="src"><pre><code class="input"><TMPL_VAR NAME="src"></code></pre></TMPL_IF> diff --git a/share/templates/en_US/error_loop_grouped.tmpl b/share/templates/en_US/error_loop_grouped.tmpl index 8db0ca5..fc2c9fa 100644 --- a/share/templates/en_US/error_loop_grouped.tmpl +++ b/share/templates/en_US/error_loop_grouped.tmpl @@ -9,8 +9,9 @@ <ul> <TMPL_LOOP NAME="instances"> <li> - <em>Line <TMPL_IF NAME="opt_show_source"><a href="#line-<TMPL_VAR NAME="line" - ESCAPE="HTML">"></TMPL_IF><TMPL_VAR NAME="line" ESCAPE="HTML"><TMPL_IF NAME="opt_show_source"></a></TMPL_IF>, + <TMPL_IF NAME="uri">(<TMPL_IF NAME="uri_is_file">Validator local file "<TMPL_VAR NAME="uri" ESCAPE="HTML">"<TMPL_ELSE><a href="<TMPL_VAR NAME="uri" ESCAPE="HTML">"><TMPL_VAR NAME="uri" ESCAPE="HTML"></a></TMPL_IF>)</TMPL_IF> + <em>Line <TMPL_IF NAME="opt_show_source"><TMPL_UNLESS NAME="uri"><a href="#line-<TMPL_VAR NAME="line" + ESCAPE="HTML">"></TMPL_UNLESS></TMPL_IF><TMPL_VAR NAME="line" ESCAPE="HTML"><TMPL_IF NAME="opt_show_source"><TMPL_UNLESS NAME="uri"></a></TMPL_UNLESS></TMPL_IF>, column <TMPL_VAR NAME="char" ESCAPE="HTML"></em>: <span><TMPL_VAR NAME="msg" ESCAPE="HTML"></span> <TMPL_IF NAME="src"><pre><code class="input"><TMPL_VAR NAME="src"></code></pre></TMPL_IF> |