Skip to content

Commit

Permalink
Ignore certain HTML validity errors
Browse files Browse the repository at this point in the history
We use the ugc (user generated content) value for no-follow links since #2855
this is not yet supported in the validator.

This patch introduces a list of ignored error messages.
  • Loading branch information
splitbrain committed Oct 31, 2019
1 parent 0af8c6f commit fc21b37
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion _test/tests/general/general_html.test.php
Expand Up @@ -7,6 +7,10 @@
*/
class general_html_test extends DokuWikiTest
{
/** @var string[] we consider these hits shortcomings in the validator and not errors */
protected $allowedErrors = [
'The string “ugc” is not a registered keyword.',
];

/**
* List of requests to check for validity
Expand Down Expand Up @@ -36,7 +40,7 @@ public function requestProvider()
*/
protected function validate($html)
{
$http = new HTTPClient();
$http = new \dokuwiki\HTTP\DokuHTTPClient();
$http->headers['Content-Type'] = 'text/html; charset=utf-8';
$result = $http->post('https://validator.w3.org/nu/?out=json&level=error', $html);

Expand All @@ -62,11 +66,23 @@ protected function listErrors($result)
{
$errors = [];
foreach ($result['messages'] as $msg) {
if ($this->isAllowedError($msg['message'])) continue;
$errors[] = "" . $msg['message'] . "\n" . $msg['extract'] . "\n";
}
return $errors;
}

/**
* Is the given string an allowed error that should be skipped?
*
* @param string $string
* @return bool
*/
protected function isAllowedError($string)
{
$re = join('|', array_map('preg_quote_cb', $this->allowedErrors));
return (bool)preg_match("/$re/", $string);
}

/**
* @dataProvider requestProvider
Expand Down

0 comments on commit fc21b37

Please sign in to comment.