1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 07:25:07 +00:00

LibWeb: Be more forgiving when adding source positions in HTMLTokenizer

This patch changes HTMLTokenizer::nth_last_position to not fail if the
requested position is not available. Rather, it will just return (0-0).

While this is not the correct solution, it prevents the tokenizer from
crashing just because it cannot find a source position. This should only
affect SyntaxHighlighter.
This commit is contained in:
Max Wipfli 2021-06-04 11:31:43 +02:00 committed by Ali Mohammad Pur
parent 93d830b5cc
commit 932161e581
3 changed files with 16 additions and 5 deletions

View file

@ -207,6 +207,15 @@ Optional<u32> HTMLTokenizer::peek_code_point(size_t offset) const
return *it;
}
HTMLToken::Position HTMLTokenizer::nth_last_position(size_t n)
{
if (n + 1 > m_source_positions.size()) {
dbgln_if(TOKENIZER_TRACE_DEBUG, "(Tokenizer::nth_last_position) Invalid position requested: {}th-last of {}. Returning (0-0).", n, m_source_positions.size());
return HTMLToken::Position { 0, 0 };
};
return m_source_positions.at(m_source_positions.size() - 1 - n);
}
Optional<HTMLToken> HTMLTokenizer::next_token()
{
{
@ -2639,7 +2648,7 @@ void HTMLTokenizer::will_emit(HTMLToken& token)
{
if (token.is_start_tag())
m_last_emitted_start_tag = token;
token.m_end_position = m_source_positions.last();
token.m_end_position = nth_last_position(0);
}
bool HTMLTokenizer::current_end_tag_token_is_appropriate() const