Adding more error reporting to html validator.
This commit is contained in:
parent
eae1f3fffe
commit
e028e5a258
3
Block.pm
3
Block.pm
@ -298,7 +298,8 @@ sub validate_htmlarea {
|
||||
return ($tidied, undef);
|
||||
|
||||
# If the return from check_xhtml is one or more digits, it is an error count
|
||||
} elsif($valid =~ /^\d+$/) {
|
||||
} elsif($valid =~ /^\d+:/) {
|
||||
$valid =~ s/^\d+://;
|
||||
return ($tidied, $self -> {"template"} -> replace_langvar("BLOCK_VALIDATE_CHKERRS", "", {"***field***" => $settings -> {"nicename"},
|
||||
"***error***" => $valid}));
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
## @file
|
||||
# HTML validation and checking functions. This file contains functions to
|
||||
# support the cleaning and checking of html using a combination of
|
||||
# support the cleaning and checking of html using a combination of
|
||||
# HTML::Scrubber to do first-stage cleaning, HTML::Tidy to clear up the
|
||||
# content as needed, and the W3C validator via the WebService::Validator::HTML::W3C
|
||||
# to ensure that the xhtml generated by HTML::Tidy is valid.
|
||||
@ -42,22 +42,22 @@ our $VERSION = 1.0;
|
||||
|
||||
# List of tags we are going to let through, lifted from the security
|
||||
# discussion on http://wiki.moxiecode.com/index.php/TinyMCE:Security
|
||||
# Several tags removed to make xhtml conformance easier and to remove
|
||||
# Several tags removed to make xhtml conformance easier and to remove
|
||||
# deprecated and eyestabbery.
|
||||
my @allow = ("a", "b", "blockquote", "br", "caption", "col", "colgroup", "comment",
|
||||
"em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "li", "ol", "p",
|
||||
"pre", "small", "span", "strong", "sub", "sup", "table", "tbody", "td",
|
||||
my @allow = ("a", "b", "blockquote", "br", "caption", "col", "colgroup", "comment",
|
||||
"em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "li", "ol", "p",
|
||||
"pre", "small", "span", "strong", "sub", "sup", "table", "tbody", "td",
|
||||
"tfoot", "th", "thead", "tr", "tt", "ul");
|
||||
|
||||
# Explicit rules for allowed tags, required to provide per-tag tweaks to the filter.
|
||||
my @rules = (
|
||||
img => {
|
||||
src => qr{^(?:http|https)://}i,
|
||||
alt => 1,
|
||||
alt => 1,
|
||||
style => 1,
|
||||
width => 1,
|
||||
height => 1,
|
||||
'*' => 0,
|
||||
'*' => 0,
|
||||
},
|
||||
a => {
|
||||
href => qr{^(?:http|https)://}i,
|
||||
@ -131,7 +131,7 @@ sub scrub_html {
|
||||
default => \@default,
|
||||
comment => 0,
|
||||
process => 0);
|
||||
|
||||
|
||||
# fix problems with the parser setup. This is hacky and nasty,
|
||||
# but from CPAN's bug tracker, this appears to have been present for
|
||||
# the past 3 years at least.
|
||||
@ -153,7 +153,7 @@ sub scrub_html {
|
||||
# HTML::Tidy related code
|
||||
|
||||
## @fn $ tidy_html($html, $options)
|
||||
# Pass a chunk of html through htmltidy. This should produce well-formed xhtml
|
||||
# Pass a chunk of html through htmltidy. This should produce well-formed xhtml
|
||||
# that can be passed on to the validator to check.
|
||||
#
|
||||
# @param html The string containing html to tidy.
|
||||
@ -173,13 +173,13 @@ sub tidy_html {
|
||||
# WebService::Validator::HTML::W3C related code
|
||||
|
||||
## @fn @ check_xhtml($xhtml, $options)
|
||||
# Check that the xhtml is valid by passing it through the W3C validator service.
|
||||
# If this is unable to contact the validation service, it will return the reason,
|
||||
# Check that the xhtml is valid by passing it through the W3C validator service.
|
||||
# If this is unable to contact the validation service, it will return the reason,
|
||||
# otherwise the number of errors will be returned (0 indicates that the xhtml
|
||||
# passed validation with no errors)
|
||||
#
|
||||
# @param xhtml The xhtml to validate with the W3C validator
|
||||
# @param options A hash containing options to pass to the validator module.
|
||||
# @param options A hash containing options to pass to the validator module.
|
||||
# Currently supports 'timeout' and 'uri'.
|
||||
# @return The number of errors during validation (0 = valid), or a string
|
||||
# from the validator module explaining why the validation bombed.
|
||||
@ -196,11 +196,16 @@ sub check_xhtml {
|
||||
return 0
|
||||
if($validator -> is_valid());
|
||||
|
||||
my $errs = "";
|
||||
foreach my $err (@{$validator -> errors}) {
|
||||
$errs .= $err -> msg." at line ".$err -> line."<br/>";
|
||||
}
|
||||
|
||||
# otherwise, the xhtml is not valid, so return the error count
|
||||
return $validator -> num_errors();
|
||||
return $validator -> num_errors().":$errs";
|
||||
}
|
||||
|
||||
# Get here and the validation request fell over, return the 'oh shit' result...
|
||||
# Get here and the validation request fell over, return the 'oh shit' result...
|
||||
return $validator -> validator_error();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user