Skip to content

Fix GH-17486: Incorrect error line numbers reported in Dom\HTMLDocument::createFromString #17491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ext/dom/html_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,13 @@ PHP_METHOD(Dom_HTMLDocument, createFromString)
if (!result) {
goto fail_oom;
}

/* In the string case we have a single buffer that acts as a sliding window.
* The `current_input_characters` field starts pointing at the start of the buffer, but needs to slide along the
* sliding window as well. */
if (application_data.current_input_characters) {
application_data.current_input_characters += chunk_size;
}
}

if (!dom_parse_decode_encode_finish(&ctx, document, parser, &decoding_encoding_ctx, &tokenizer_error_offset, &tree_error_offset)) {
Expand Down
39 changes: 39 additions & 0 deletions ext/dom/tests/modern/html/parser/gh17486.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
GH-17486 (Incorrect error line numbers reported in Dom\HTMLDocument::createFromString)
--EXTENSIONS--
dom
--INI--
error_reporting=E_ALL
--CREDITS--
xPaw
--FILE--
<?php

$repeated = str_repeat('a', 50000);

$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<body>
<svg>
<path d="{$repeated}" />
</svg>
<div>&#x0;</div>
</body>
</html>
HTML;

\Dom\HTMLDocument::createFromString($html);

file_put_contents(__DIR__ . '/gh17486.tmp', $html);
\Dom\HTMLDocument::createFromFile(__DIR__ . '/gh17486.tmp');

?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh17486.tmp');
?>
--EXPECTF--
Warning: Dom\HTMLDocument::createFromString(): tokenizer error null-character-reference in Entity, line: 7, column: 9 in %s on line %d

Warning: Dom\HTMLDocument::createFromFile(): tokenizer error null-character-reference in %s line: 7, column: 9 in %s on line %d
Loading