1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +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

@ -57,9 +57,11 @@ String HTMLToken::to_string() const
builder.append("' }");
}
builder.appendff("@{}:{}-{}:{}",
m_start_position.line, m_start_position.column,
m_end_position.line, m_end_position.column);
if (type() == HTMLToken::Type::Character) {
builder.appendff("@{}:{}", m_start_position.line, m_start_position.column);
} else {
builder.appendff("@{}:{}-{}:{}", m_start_position.line, m_start_position.column, m_end_position.line, m_end_position.column);
}
return builder.to_string();
}