mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Fix parsing of character references in attribute values
This commit is contained in:
parent
0505a815f7
commit
13c7d55320
Notes:
sideshowbarker
2024-07-19 17:22:45 +09:00
Author: https://github.com/lo-v-ol 🔰 Commit: https://github.com/SerenityOS/serenity/commit/13c7d553201 Pull-request: https://github.com/SerenityOS/serenity/pull/9001
2 changed files with 23 additions and 13 deletions
|
@ -57,7 +57,7 @@ using Token = Web::HTML::HTMLToken;
|
|||
|
||||
#define EXPECT_TAG_TOKEN_ATTRIBUTE(name, value) \
|
||||
VERIFY(last_token); \
|
||||
EXPECT_EQ(last_token->attribute(#name), #value);
|
||||
EXPECT_EQ(last_token->attribute(#name), value);
|
||||
|
||||
#define EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(count) \
|
||||
VERIFY(last_token); \
|
||||
|
@ -124,7 +124,7 @@ TEST_CASE(unquoted_attributes)
|
|||
BEGIN_ENUMERATION(tokens);
|
||||
EXPECT_START_TAG_TOKEN(p);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(1);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, bar);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, "bar");
|
||||
EXPECT_END_OF_FILE_TOKEN();
|
||||
END_ENUMERATION();
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ TEST_CASE(single_quoted_attributes)
|
|||
BEGIN_ENUMERATION(tokens);
|
||||
EXPECT_START_TAG_TOKEN(p);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(1);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, bar);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, "bar");
|
||||
EXPECT_END_OF_FILE_TOKEN();
|
||||
END_ENUMERATION();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ TEST_CASE(double_quoted_attributes)
|
|||
BEGIN_ENUMERATION(tokens);
|
||||
EXPECT_START_TAG_TOKEN(p);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(1);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, bar);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, "bar");
|
||||
EXPECT_END_OF_FILE_TOKEN();
|
||||
END_ENUMERATION();
|
||||
}
|
||||
|
@ -157,9 +157,22 @@ TEST_CASE(multiple_attributes)
|
|||
BEGIN_ENUMERATION(tokens);
|
||||
EXPECT_START_TAG_TOKEN(p);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(3);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, bar);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(baz, foobar);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo2, bar2);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, "bar");
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(baz, "foobar");
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo2, "bar2");
|
||||
EXPECT_END_OF_FILE_TOKEN();
|
||||
END_ENUMERATION();
|
||||
}
|
||||
|
||||
TEST_CASE(character_reference_in_attribute)
|
||||
{
|
||||
auto tokens = run_tokenizer("<p foo=a&b bar='a&b' baz=\"a&b\">");
|
||||
BEGIN_ENUMERATION(tokens);
|
||||
EXPECT_START_TAG_TOKEN(p);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE_COUNT(3);
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(foo, "a&b");
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(bar, "a&b");
|
||||
EXPECT_TAG_TOKEN_ATTRIBUTE(baz, "a&b");
|
||||
EXPECT_END_OF_FILE_TOKEN();
|
||||
END_ENUMERATION();
|
||||
}
|
||||
|
|
|
@ -1179,9 +1179,8 @@ _StartOfFunction:
|
|||
}
|
||||
ON('&')
|
||||
{
|
||||
m_current_token.last_attribute().value = consume_current_builder();
|
||||
m_return_state = State::AttributeValueDoubleQuoted;
|
||||
SWITCH_TO(CharacterReference);
|
||||
SWITCH_TO_WITH_UNCLEAN_BUILDER(CharacterReference);
|
||||
}
|
||||
ON(0)
|
||||
{
|
||||
|
@ -1211,9 +1210,8 @@ _StartOfFunction:
|
|||
}
|
||||
ON('&')
|
||||
{
|
||||
m_current_token.last_attribute().value = consume_current_builder();
|
||||
m_return_state = State::AttributeValueSingleQuoted;
|
||||
SWITCH_TO(CharacterReference);
|
||||
SWITCH_TO_WITH_UNCLEAN_BUILDER(CharacterReference);
|
||||
}
|
||||
ON(0)
|
||||
{
|
||||
|
@ -1244,9 +1242,8 @@ _StartOfFunction:
|
|||
}
|
||||
ON('&')
|
||||
{
|
||||
m_current_token.last_attribute().value = consume_current_builder();
|
||||
m_return_state = State::AttributeValueUnquoted;
|
||||
SWITCH_TO(CharacterReference);
|
||||
SWITCH_TO_WITH_UNCLEAN_BUILDER(CharacterReference);
|
||||
}
|
||||
ON('>')
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue