Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle more cases with < folloed by character data (#705) #721

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions bleach/html5lib_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,17 @@ def __iter__(self):
# followed by a series of characters. It's treated as a tag
# name that abruptly ends, but we should treat that like
# character data
yield {
"type": TAG_TOKEN_TYPE_CHARACTERS,
"data": "<" + self.currentToken["name"],
}
yield {"type": TAG_TOKEN_TYPE_CHARACTERS, "data": self.stream.get_tag()}
elif last_error_token["data"] in (
"eof-in-attribute-name",
"eof-in-attribute-value-no-quotes",
):
# Handle the case where the text being parsed ends with <
# followed by a series of characters and then space and then
# more characters. It's treated as a tag name followed by an
# attribute that abruptly ends, but we should treat that like
# character data.
yield {"type": TAG_TOKEN_TYPE_CHARACTERS, "data": self.stream.get_tag()}
else:
yield last_error_token

Expand Down
4 changes: 4 additions & 0 deletions tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def test_bare_entities_get_escaped_correctly(text, expected):
("<y", "&lt;y"),
("x < y", "x &lt; y"),
("<y>", "&lt;y&gt;"),
# this is an eof-in-attribute-name parser error
("<some thing", "&lt;some thing"),
# this is an eof-in-attribute-value-no-quotes parser error
("<some thing=foo", "&lt;some thing=foo"),
],
)
def test_lessthan_escaping(text, expected):
Expand Down