diff --git a/ext/dom/html_document.c b/ext/dom/html_document.c index ed7454dd89d43..240fa71a0cca7 100644 --- a/ext/dom/html_document.c +++ b/ext/dom/html_document.c @@ -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)) { diff --git a/ext/dom/tests/modern/html/parser/gh17486.phpt b/ext/dom/tests/modern/html/parser/gh17486.phpt new file mode 100644 index 0000000000000..4d7ddee7dde96 --- /dev/null +++ b/ext/dom/tests/modern/html/parser/gh17486.phpt @@ -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-- + + + + + + +
+ + +HTML; + +\Dom\HTMLDocument::createFromString($html); + +file_put_contents(__DIR__ . '/gh17486.tmp', $html); +\Dom\HTMLDocument::createFromFile(__DIR__ . '/gh17486.tmp'); + +?> +--CLEAN-- + +--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