mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +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:
parent
93d830b5cc
commit
932161e581
3 changed files with 16 additions and 5 deletions
|
@ -57,9 +57,11 @@ String HTMLToken::to_string() const
|
||||||
builder.append("' }");
|
builder.append("' }");
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.appendff("@{}:{}-{}:{}",
|
if (type() == HTMLToken::Type::Character) {
|
||||||
m_start_position.line, m_start_position.column,
|
builder.appendff("@{}:{}", m_start_position.line, m_start_position.column);
|
||||||
m_end_position.line, m_end_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();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,15 @@ Optional<u32> HTMLTokenizer::peek_code_point(size_t offset) const
|
||||||
return *it;
|
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()
|
Optional<HTMLToken> HTMLTokenizer::next_token()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -2639,7 +2648,7 @@ void HTMLTokenizer::will_emit(HTMLToken& token)
|
||||||
{
|
{
|
||||||
if (token.is_start_tag())
|
if (token.is_start_tag())
|
||||||
m_last_emitted_start_tag = token;
|
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
|
bool HTMLTokenizer::current_end_tag_token_is_appropriate() const
|
||||||
|
|
|
@ -147,7 +147,7 @@ private:
|
||||||
bool consumed_as_part_of_an_attribute() const;
|
bool consumed_as_part_of_an_attribute() const;
|
||||||
|
|
||||||
void restore_to(const Utf8CodePointIterator& new_iterator);
|
void restore_to(const Utf8CodePointIterator& new_iterator);
|
||||||
auto& nth_last_position(size_t n = 0) { return m_source_positions.at(m_source_positions.size() - 1 - n); }
|
HTMLToken::Position nth_last_position(size_t n = 0);
|
||||||
|
|
||||||
State m_state { State::Data };
|
State m_state { State::Data };
|
||||||
State m_return_state { State::Data };
|
State m_return_state { State::Data };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue