Browse Source

Fix remaining error positions

ns
J. King 3 years ago
parent
commit
7f53465951
  1. 8
      lib/Data.php
  2. 9
      lib/ParseError.php
  3. 26
      tests/cases/TestTokenizer.php
  4. 2
      tests/cases/TestTreeConstructor.php

8
lib/Data.php

@ -220,11 +220,15 @@ class Data {
/** Returns an indexed array with the line and column positions of the requested offset from the current position */
public function whereIs(int $relativePos): array {
if ($this->eof) {
$relativePos++;
if ($this->astrals[$this->data->posChar()] ?? false) {
$relativePos++;
}
}
if ($relativePos === 0) {
if (!$this->_column && $this->_line > 1) {
return [$this->_line - 1, $this->newlines[$this->data->posChar()] + 1];
} elseif ($this->astrals[$this->data->posChar()] ?? false) {
return [$this->_line, $this->_column + 1];
} else {
return [$this->_line, $this->_column];
}

9
lib/ParseError.php

@ -146,12 +146,6 @@ class ParseError {
];
const REPORT_OFFSETS = [
self::EOF_IN_TAG => 1,
self::EOF_IN_COMMENT => 1,
self::EOF_IN_DOCTYPE => 1,
self::EOF_BEFORE_TAG_NAME => 1,
self::EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT => 1,
self::EOF_IN_CDATA => 1,
self::INCORRECTLY_OPENED_COMMENT => 1,
self::SURROGATE_CHARACTER_REFERENCE => 1,
self::CHARACTER_REFERENCE_OUTSIDE_UNICODE_RANGE => 1,
@ -159,7 +153,8 @@ class ParseError {
self::ABSENCE_OF_DIGITS_IN_NUMERIC_CHARACTER_REFERENCE => 1,
self::NULL_CHARACTER_REFERENCE => 1,
self::MISSING_SEMICOLON_AFTER_CHARACTER_REFERENCE => 1,
self::CONTROL_CHARACTER_REFERENCE => 1,
self::UNKNOWN_NAMED_CHARACTER_REFERENCE => 1,
];
public function setHandler() {

26
tests/cases/TestTokenizer.php

@ -189,6 +189,32 @@ class TestTokenizer extends \PHPUnit\Framework\TestCase {
case ["<!\u{B}", ["Data state"]]:
$test['errors'] = array_reverse($test['errors']);
break;
// eof-in-<whatever> positions in some tests don't make sense
// https://github.com/html5lib/html5lib-tests/issues/125
case ["", ["CDATA section state"]]:
// there is no position 2
$test['errors'][0]['col']--;
break;
case ["\u{A}", ["CDATA section state"]]:
// the line break is, for some reason, not counted in the test
$test['errors'][0]['line']++;
$test['errors'][0]['col'] = 1;
break;
case ["<!----!\r\n>", ["Data state"]]:
case ["<!----!\n>", ["Data state"]]:
case ["<!----!\r>", ["Data state"]]:
// the line break is, for some reason, not counted in the test
$test['errors'][0]['line']++;
$test['errors'][0]['col'] = 2;
break;
case ["<!----! >", ["Data state"]]:
$test['errors'][0]['col']++;
break;
case [hex2bin("f4808080"), ["CDATA section state"]]:
case [hex2bin("3bf4808080"), ["CDATA section state"]]:
// malpaired surrogates count as two characters
$test['errors'][0]['col']++;
break;
}
}
}

2
tests/cases/TestTreeConstructor.php

@ -91,7 +91,7 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
$this->assertEquals($exp, $act, $treeBuilder->debugLog);
if ($errors !== false) {
// If $errors is false, the test does not include errors when there are in fact errors
//$this->assertCount(sizeof($errors), $actualErrors, var_export($errors, true).var_export($actualErrors, true));
$this->assertCount(sizeof($errors), $actualErrors, var_export($errors, true).var_export($actualErrors, true));
}
}

Loading…
Cancel
Save