1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 13:17:36 +00:00

LibWeb: Pass correct values to would_start_an_identifier()

Same as with would_start_a_number(), we were skipping a code point.
This commit is contained in:
Sam Atkins 2021-12-24 16:22:57 +00:00 committed by Andreas Kling
parent bb82ee5530
commit 269a24d4ca
2 changed files with 5 additions and 11 deletions

View file

@ -844,7 +844,7 @@ Token Tokenizer::consume_a_numeric_token()
auto number = consume_a_number(); auto number = consume_a_number();
// If the next 3 input code points would start an identifier, then: // If the next 3 input code points would start an identifier, then:
if (would_start_an_identifier()) { if (would_start_an_identifier(peek_triplet())) {
// 1. Create a <dimension-token> with the same value and type flag as number, // 1. Create a <dimension-token> with the same value and type flag as number,
// and a unit set initially to the empty string. // and a unit set initially to the empty string.
auto token = create_new_token(Token::Type::Dimension); auto token = create_new_token(Token::Type::Dimension);
@ -948,11 +948,6 @@ bool Tokenizer::is_valid_escape_sequence(U32Twin values)
return true; return true;
} }
bool Tokenizer::would_start_an_identifier()
{
return would_start_an_identifier(peek_triplet());
}
// https://www.w3.org/TR/css-syntax-3/#would-start-an-identifier // https://www.w3.org/TR/css-syntax-3/#would-start-an-identifier
bool Tokenizer::would_start_an_identifier(U32Triplet values) bool Tokenizer::would_start_an_identifier(U32Triplet values)
{ {
@ -1143,7 +1138,7 @@ Token Tokenizer::consume_a_token()
// 2. If the next 3 input code points would start an identifier, set the <hash-token>s // 2. If the next 3 input code points would start an identifier, set the <hash-token>s
// type flag to "id". // type flag to "id".
if (would_start_an_identifier()) if (would_start_an_identifier(peek_triplet()))
token.m_hash_type = Token::HashType::Id; token.m_hash_type = Token::HashType::Id;
// 3. Consume a name, and set the <hash-token>s value to the returned string. // 3. Consume a name, and set the <hash-token>s value to the returned string.
@ -1222,7 +1217,7 @@ Token Tokenizer::consume_a_token()
// Otherwise, if the input stream starts with an identifier, reconsume the current // Otherwise, if the input stream starts with an identifier, reconsume the current
// input code point, consume an ident-like token, and return it. // input code point, consume an ident-like token, and return it.
if (would_start_an_identifier()) { if (would_start_an_identifier(start_of_input_stream_triplet())) {
reconsume_current_input_code_point(); reconsume_current_input_code_point();
return consume_an_ident_like_token(); return consume_an_ident_like_token();
} }
@ -1282,7 +1277,7 @@ Token Tokenizer::consume_a_token()
dbgln_if(CSS_TOKENIZER_DEBUG, "is at"); dbgln_if(CSS_TOKENIZER_DEBUG, "is at");
// If the next 3 input code points would start an identifier, consume a name, create // If the next 3 input code points would start an identifier, consume a name, create
// an <at-keyword-token> with its value set to the returned value, and return it. // an <at-keyword-token> with its value set to the returned value, and return it.
if (would_start_an_identifier()) { if (would_start_an_identifier(peek_triplet())) {
auto name = consume_a_name(); auto name = consume_a_name();
return create_value_token(Token::Type::AtKeyword, name); return create_value_token(Token::Type::AtKeyword, name);
} }

View file

@ -99,8 +99,7 @@ private:
void consume_as_much_whitespace_as_possible(); void consume_as_much_whitespace_as_possible();
void reconsume_current_input_code_point(); void reconsume_current_input_code_point();
[[nodiscard]] static bool is_valid_escape_sequence(U32Twin); [[nodiscard]] static bool is_valid_escape_sequence(U32Twin);
[[nodiscard]] bool would_start_an_identifier(); [[nodiscard]] static bool would_start_an_identifier(U32Triplet);
[[nodiscard]] bool would_start_an_identifier(U32Triplet);
[[nodiscard]] static bool would_start_a_number(U32Triplet); [[nodiscard]] static bool would_start_a_number(U32Triplet);
String m_decoded_input; String m_decoded_input;