mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-11-01 05:41:01 +00:00
LibWeb: Set the correct end position of HTML attribute names
We were previously setting the end position of attribute names in self-
closing HTML tags to the end of the attribute value. To illustrate the
previous behavior, consider this tag and its attribute's start and end
positions (shown inclusively below):
<meta charset="UTF-8" />
^ name start
^ value start
^ value end
^ name end
Rather than setting the end position of the attribute name when we parse
the closing slash, ensure the end position is already set while we are
in the AttributeName state. We now have:
<meta charset="UTF-8" />
^ name start
^ name end
^ value start
^ value end
The tokenizer unit test has been extended to test these positions.
This commit is contained in:
parent
5b2bc90b50
commit
5a2bf7fdd1
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/trflynn89
Commit: 5a2bf7fdd1
Pull-request: https://github.com/SerenityOS/serenity/pull/20756
3 changed files with 46 additions and 19 deletions
|
|
@ -1051,8 +1051,6 @@ _StartOfFunction:
|
|||
}
|
||||
ON('/')
|
||||
{
|
||||
if (m_current_token.has_attributes())
|
||||
m_current_token.last_attribute().name_end_position = nth_last_position(1);
|
||||
RECONSUME_IN(AfterAttributeName);
|
||||
}
|
||||
ON('>')
|
||||
|
|
@ -1108,21 +1106,25 @@ _StartOfFunction:
|
|||
{
|
||||
ON_WHITESPACE
|
||||
{
|
||||
m_current_token.last_attribute().name_end_position = nth_last_position(1);
|
||||
m_current_token.last_attribute().local_name = consume_current_builder();
|
||||
RECONSUME_IN(AfterAttributeName);
|
||||
}
|
||||
ON('/')
|
||||
{
|
||||
m_current_token.last_attribute().name_end_position = nth_last_position(1);
|
||||
m_current_token.last_attribute().local_name = consume_current_builder();
|
||||
RECONSUME_IN(AfterAttributeName);
|
||||
}
|
||||
ON('>')
|
||||
{
|
||||
m_current_token.last_attribute().name_end_position = nth_last_position(1);
|
||||
m_current_token.last_attribute().local_name = consume_current_builder();
|
||||
RECONSUME_IN(AfterAttributeName);
|
||||
}
|
||||
ON_EOF
|
||||
{
|
||||
m_current_token.last_attribute().name_end_position = nth_last_position(1);
|
||||
m_current_token.last_attribute().local_name = consume_current_builder();
|
||||
RECONSUME_IN(AfterAttributeName);
|
||||
}
|
||||
|
|
@ -1196,7 +1198,7 @@ _StartOfFunction:
|
|||
{
|
||||
m_current_token.add_attribute({});
|
||||
if (!m_source_positions.is_empty())
|
||||
m_current_token.last_attribute().name_start_position = m_source_positions.last();
|
||||
m_current_token.last_attribute().name_start_position = nth_last_position(1);
|
||||
RECONSUME_IN(AttributeName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue