Skip to content

Commit c7a8195

Browse files
committed
Fix phpGH-17486: Incorrect error line numbers reported in Dom\HTMLDocument::createFromString
1 parent 27fbdc1 commit c7a8195

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

ext/dom/html_document.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,11 @@ PHP_METHOD(Dom_HTMLDocument, createFromString)
880880
if (!result) {
881881
goto fail_oom;
882882
}
883+
884+
/* In the string case we have a single buffer that acts as a sliding window.
885+
* The `current_input_characters` field starts pointing at the start of the buffer, but needs to slide along the
886+
* sliding window as well. */
887+
application_data.current_input_characters += chunk_size;
883888
}
884889

885890
if (!dom_parse_decode_encode_finish(&ctx, document, parser, &decoding_encoding_ctx, &tokenizer_error_offset, &tree_error_offset)) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
GH-17486 (Incorrect error line numbers reported in Dom\HTMLDocument::createFromString)
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
xPaw
7+
--FILE--
8+
<?php
9+
10+
$repeated = str_repeat('a', 50000);
11+
12+
$html = <<<HTML
13+
<!DOCTYPE html>
14+
<html lang="en">
15+
<body>
16+
<svg>
17+
<path d="{$repeated}" />
18+
</svg>
19+
<div>&#xa;</div>
20+
</body>
21+
</html>
22+
HTML;
23+
24+
\Dom\HTMLDocument::createFromString($html);
25+
26+
file_put_contents(__DIR__ . '/gh17486.tmp', $html);
27+
\Dom\HTMLDocument::createFromFile(__DIR__ . '/gh17486.tmp');
28+
29+
?>
30+
--CLEAN--
31+
<?php
32+
@unlink(__DIR__ . '/gh17486.tmp');
33+
?>
34+
--EXPECTF--
35+
Warning: Dom\HTMLDocument::createFromString(): tokenizer error control-character-reference in Entity, line: 7, column: 9 in %s on line %d
36+
37+
Warning: Dom\HTMLDocument::createFromFile(): tokenizer error control-character-reference in %sgh17486.tmp, line: 7, column: 9 in %s on line %d

0 commit comments

Comments
 (0)