mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
The RehighlightState designated initializer used `.position = {}`
which invokes TextPosition's default constructor, initializing line
and column to 0xFFFFFFFF (the "invalid" sentinel). This overrode
the struct's default member initializer of { 0, 0 }.
When advance_position() processed the first newline, it incremented
0xFFFFFFFF to 0x100000000, producing line numbers in the billions.
These bogus positions propagated into folding regions, causing an
out-of-bounds crash in Document::set_folding_regions() when viewing
page source on pages with <script> blocks.
Fix by explicitly initializing position to { 0, 0 }.
Fixes #8529.
19 lines
607 B
C++
19 lines
607 B
C++
/*
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTest/TestCase.h>
|
|
#include <LibURL/URL.h>
|
|
#include <LibWebView/SourceHighlighter.h>
|
|
|
|
TEST_CASE(highlight_script_with_braces)
|
|
{
|
|
// Regression test for https://github.com/LadybirdBrowser/ladybird/issues/8529
|
|
auto source = "<script>\nfunction foo() {\n return 1;\n}\n</script>"_string;
|
|
URL::URL base_url {};
|
|
auto result = WebView::highlight_source({}, base_url, source, Syntax::Language::HTML, WebView::HighlightOutputMode::SourceOnly);
|
|
EXPECT(!result.is_empty());
|
|
}
|