LibWeb: Fix parsing of character references in attribute values

This commit is contained in:
ovf 2021-07-24 23:15:47 +01:00 committed by Andreas Kling
parent 0505a815f7
commit 13c7d55320
Notes: sideshowbarker 2024-07-19 17:22:45 +09:00
2 changed files with 23 additions and 13 deletions

View file

@ -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&amp;b bar='a&amp;b' baz=\"a&amp;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();
}

View file

@ -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('>')
{