From 69367194a6d04bf124dd0b1697c69a75489122a7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 23 Nov 2024 18:30:01 +0100 Subject: [PATCH] LibWeb: Make HTML tokenizer stop at insertion point after state switch If we reach the insertion point at the same time as we switch to another tokenizer state, we have to bail immediately without proceeding with the next code point. Otherwise we'd fetch the next token, get an EOF marker, and then proceed as if we're at the end of the input stream, even though more data may be coming (with more calls to document.write()..) --- Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp | 14 ++++++++------ .../html/syntax/parsing/ambiguous-ampersand.txt | 8 ++++---- .../document-write/003.txt | 4 ++-- .../document-write/007.txt | 4 ++-- .../document-write/010.txt | 4 ++-- .../document-write/011.txt | 4 ++-- .../document-write/014.txt | 4 ++-- .../document-write/015.txt | 4 ++-- .../document-write/017.txt | 4 ++-- .../document-write/033.txt | 4 ++-- .../document-write/035.txt | 4 ++-- .../document-write/038.txt | 4 ++-- .../document-write/039.txt | 4 ++-- .../document-write/046.txt | 4 ++-- .../document-write/049.txt | 4 ++-- .../document-write/iframe_002.txt | 4 ++-- .../document-write/iframe_008.txt | 4 ++-- .../document-write/iframe_009.txt | 4 ++-- 18 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index fca8292ec29..c13ce25192b 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -30,12 +30,14 @@ namespace Web::HTML { SWITCH_TO_WITH_UNCLEAN_BUILDER(new_state); \ } while (0) -#define SWITCH_TO_WITH_UNCLEAN_BUILDER(new_state) \ - do { \ - will_switch_to(State::new_state); \ - m_state = State::new_state; \ - CONSUME_NEXT_INPUT_CHARACTER; \ - goto new_state; \ +#define SWITCH_TO_WITH_UNCLEAN_BUILDER(new_state) \ + do { \ + will_switch_to(State::new_state); \ + m_state = State::new_state; \ + if (stop_at_insertion_point == StopAtInsertionPoint::Yes && is_insertion_point_reached()) \ + return {}; \ + CONSUME_NEXT_INPUT_CHARACTER; \ + goto new_state; \ } while (0) #define RECONSUME_IN(new_state) \ diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/syntax/parsing/ambiguous-ampersand.txt b/Tests/LibWeb/Text/expected/wpt-import/html/syntax/parsing/ambiguous-ampersand.txt index 4dcb3893808..8879e4e2e1b 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/syntax/parsing/ambiguous-ampersand.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/syntax/parsing/ambiguous-ampersand.txt @@ -6,9 +6,9 @@ Rerun Found 3 tests -1 Pass -2 Fail +2 Pass +1 Fail Details -Result Test Name MessageFail Check number of divs +Result Test Name MessagePass Check number of divs Pass Check div structure: network -Fail Check div structure: document.write Cannot access property "childNodes" on undefined object "div" \ No newline at end of file +Fail Check div structure: document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/003.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/003.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/003.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/003.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/007.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/007.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/007.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/007.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/010.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/010.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/010.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/010.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/011.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/011.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/011.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/011.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/014.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/014.txt index 9e0ab144835..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/014.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/014.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write Cannot access property "firstChild" on null object "document.body" \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/015.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/015.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/015.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/015.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/017.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/017.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/017.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/017.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/033.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/033.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/033.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/033.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/035.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/035.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/035.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/035.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/038.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/038.txt index a57d8db5360..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/038.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/038.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write Cannot access property "childNodes" on null object "document.body" \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/039.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/039.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/039.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/039.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/046.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/046.txt index 400fa5782b1..49a300c2d27 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/046.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/046.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write \ No newline at end of file +Result Test Name MessagePass document.write \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/049.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/049.txt index d3ff2981134..577ea5ff09a 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/049.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/049.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write plaintext \ No newline at end of file +Result Test Name MessagePass document.write plaintext \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_002.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_002.txt index b2f8a241085..38d3b78bfbe 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_002.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_002.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write into iframe \ No newline at end of file +Result Test Name MessagePass document.write into iframe \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_008.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_008.txt index 71b91782341..e649c315d7d 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_008.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_008.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write plaintext into iframe \ No newline at end of file +Result Test Name MessagePass document.write plaintext into iframe \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_009.txt b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_009.txt index 71b91782341..e649c315d7d 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_009.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/webappapis/dynamic-markup-insertion/document-write/iframe_009.txt @@ -6,6 +6,6 @@ Rerun Found 1 tests -1 Fail +1 Pass Details -Result Test Name MessageFail document.write plaintext into iframe \ No newline at end of file +Result Test Name MessagePass document.write plaintext into iframe \ No newline at end of file