From 5067a040bac9725f611ae78afb4a496abf06b1a6 Mon Sep 17 00:00:00 2001 From: Samuel Eisenhandler Date: Mon, 1 Jul 2024 22:58:16 -0400 Subject: [PATCH] LibWebView: Append remaining source after consuming all tokens Since "Character" tokens do not have an "end position", viewing source drops the source contents following the final non-"Character" token. By handling the EOF token and breaking out of the loop, we avoid this issue. (cherry picked from commit 7de669dc07956c402e0ddec76e3f214f622cf2c4) --- Userland/Libraries/LibWebView/SourceHighlighter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWebView/SourceHighlighter.cpp b/Userland/Libraries/LibWebView/SourceHighlighter.cpp index 3d162b8b1beaf7..c482fa64499f13 100644 --- a/Userland/Libraries/LibWebView/SourceHighlighter.cpp +++ b/Userland/Libraries/LibWebView/SourceHighlighter.cpp @@ -60,7 +60,7 @@ String highlight_source(URL::URL const& url, StringView source) previous_position = end_position; }; - for (auto token = tokenizer.next_token(); token.has_value() && !token->is_end_of_file(); token = tokenizer.next_token()) { + for (auto token = tokenizer.next_token(); token.has_value(); token = tokenizer.next_token()) { if (token->is_comment()) { append_source(token->start_position().byte_offset); append_source(token->end_position().byte_offset, "comment"sv); @@ -83,6 +83,8 @@ String highlight_source(URL::URL const& url, StringView source) append_source(token->end_position().byte_offset); } else { append_source(token->end_position().byte_offset); + if (token->is_end_of_file()) + break; } }