LibWeb: Explicitly disallow skipping 0 characters in HTML tokenizer
Previously, this caused the source position of an ambiguous ampersand to be incorrect.
This commit is contained in:
parent
9037f4e832
commit
478cf4f42c
2 changed files with 11 additions and 1 deletions
|
|
@ -220,6 +220,7 @@ Optional<u32> HTMLTokenizer::next_code_point(StopAtInsertionPoint stop_at_insert
|
|||
|
||||
void HTMLTokenizer::skip(size_t count)
|
||||
{
|
||||
VERIFY(count > 0);
|
||||
if (!m_source_positions.is_empty())
|
||||
m_source_positions.append(m_source_positions.last());
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
|
@ -1725,7 +1726,7 @@ _StartOfFunction:
|
|||
auto num_consumed = m_temporary_buffer.size() - starting_consumed_count;
|
||||
if (num_consumed == 0) {
|
||||
DONT_CONSUME_NEXT_INPUT_CHARACTER;
|
||||
} else {
|
||||
} else if (num_consumed > 1) {
|
||||
skip(num_consumed - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,3 +266,12 @@ TEST_CASE(regression)
|
|||
u32 hash = hash_tokens(tokens);
|
||||
EXPECT_EQ(hash, 3657343287u);
|
||||
}
|
||||
|
||||
TEST_CASE(ambiguous_ampersand_offset)
|
||||
{
|
||||
auto tokens = run_tokenizer("&a"sv);
|
||||
auto& token = tokens.first();
|
||||
EXPECT_EQ(token.type(), Token::Type::Character);
|
||||
EXPECT_EQ(token.start_position().line, 0u);
|
||||
EXPECT_EQ(token.start_position().column, 1u);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue