Skip to content

Commit c249fbd

Browse files
AtkinsSJawesomekling
authored andcommitted
LibWeb: Correct escape handling in CSS Tokenizer
Calling is_valid_escape_sequence() with no arguments hides what it is operating on, so I have removed that, so that you must explicitly tell it what you are testing. The call from consume_a_token() was using the wrong tokens, so it returned false incorrectly. This was resulting in corrupted output when faced with this code from Acid2. (Abbreviated) ```css .parser { error: \}; } .parser { } ```
1 parent e381ca2 commit c249fbd

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Token Tokenizer::consume_a_url_token()
504504
}
505505

506506
if (is_reverse_solidus(input)) {
507-
if (is_valid_escape_sequence()) {
507+
if (is_valid_escape_sequence(peek_twin())) {
508508
token.m_value.append_code_point(consume_escaped_code_point());
509509
} else {
510510
log_parse_error();
@@ -534,7 +534,7 @@ void Tokenizer::consume_the_remnants_of_a_bad_url()
534534
return;
535535
}
536536

537-
if (is_valid_escape_sequence()) {
537+
if (is_valid_escape_sequence(peek_twin())) {
538538
[[maybe_unused]] auto cp = consume_escaped_code_point();
539539
}
540540

@@ -601,11 +601,6 @@ bool Tokenizer::starts_with_a_number(U32Triplet values)
601601
return false;
602602
}
603603

604-
bool Tokenizer::is_valid_escape_sequence()
605-
{
606-
return is_valid_escape_sequence(peek_twin());
607-
}
608-
609604
bool Tokenizer::is_valid_escape_sequence(U32Twin values)
610605
{
611606
if (!is_reverse_solidus(values.first)) {
@@ -864,7 +859,7 @@ Token Tokenizer::consume_a_token()
864859

865860
if (is_reverse_solidus(input)) {
866861
dbgln_if(CSS_TOKENIZER_TRACE, "is reverse solidus");
867-
if (is_valid_escape_sequence()) {
862+
if (is_valid_escape_sequence({ input, peek_code_point() })) {
868863
reconsume_current_input_code_point();
869864
return consume_an_ident_like_token();
870865
}

Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class Tokenizer {
9292
void consume_the_remnants_of_a_bad_url();
9393
void consume_comments();
9494
void reconsume_current_input_code_point();
95-
[[nodiscard]] bool is_valid_escape_sequence();
9695
[[nodiscard]] static bool is_valid_escape_sequence(U32Twin);
9796
[[nodiscard]] bool would_start_an_identifier();
9897
[[nodiscard]] bool would_start_an_identifier(U32Triplet);

0 commit comments

Comments
 (0)