From d3057a9c7967225e4b37edaeebfac8d5fbe0d3ab Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Wed, 5 Feb 2025 13:49:19 +0000 Subject: [PATCH] LibWeb: Preserve opening quotation in string token original source text Used by chess.com, where it stores URLs to assets in CSS URL variables. It then receives the value of them with getComputedStyle() and then getPropertyValue(). With this, it trims off the url('') wrapper with a simple slice(5, -2). Since we didn't preserve the opening quotation, it would slice off the `h` in `https` instead of the quotation. --- Libraries/LibWeb/CSS/Parser/Tokenizer.cpp | 6 +++--- .../css/getComputedStyle-url-var-serialization.txt | 1 + .../css/getComputedStyle-url-var-serialization.html | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/css/getComputedStyle-url-var-serialization.txt create mode 100644 Tests/LibWeb/Text/input/css/getComputedStyle-url-var-serialization.html diff --git a/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp b/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp index a0b1ed8ed4..6d07a58ca4 100644 --- a/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp +++ b/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp @@ -919,13 +919,13 @@ Token Tokenizer::consume_string_token(u32 ending_code_point) // code point is used. // Initially create a with its value set to the empty string. - auto start_byte_offset = current_byte_offset(); + auto original_source_text_start_byte_offset_including_quotation_mark = current_byte_offset() - 1; auto token = create_new_token(Token::Type::String); StringBuilder builder; auto make_token = [&]() -> Token { token.m_value = builder.to_fly_string_without_validation(); - token.m_original_source_text = input_since(start_byte_offset); + token.m_original_source_text = input_since(original_source_text_start_byte_offset_including_quotation_mark); return token; }; @@ -950,7 +950,7 @@ Token Tokenizer::consume_string_token(u32 ending_code_point) // , and return it. reconsume_current_input_code_point(); auto bad_string_token = create_new_token(Token::Type::BadString); - bad_string_token.m_original_source_text = input_since(start_byte_offset); + bad_string_token.m_original_source_text = input_since(original_source_text_start_byte_offset_including_quotation_mark); return bad_string_token; } diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-url-var-serialization.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-url-var-serialization.txt new file mode 100644 index 0000000000..5733c4e292 --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-url-var-serialization.txt @@ -0,0 +1 @@ +style.getPropertyValue("--test-url") = url('https://ladybird.org/') diff --git a/Tests/LibWeb/Text/input/css/getComputedStyle-url-var-serialization.html b/Tests/LibWeb/Text/input/css/getComputedStyle-url-var-serialization.html new file mode 100644 index 0000000000..d1ce73a8b6 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/getComputedStyle-url-var-serialization.html @@ -0,0 +1,13 @@ + + + +