Skip to content

Commit

Permalink
Merge pull request #572 from mozilla/fix-indexerror
Browse files Browse the repository at this point in the history
linkify: fix IndexError in convert_entity
  • Loading branch information
g-k committed Jan 20, 2021
2 parents a4ed4d2 + eb8aebd commit c66edfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bleach/html5lib_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ def convert_entity(value):
"""
if value[0] == "#":
if len(value) < 2:
return None
if value[1] in ("x", "X"):
return six.unichr(int(value[2:], 16))
return six.unichr(int(value[1:], 10))
Expand Down
11 changes: 9 additions & 2 deletions tests/test_linkify.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,15 @@ def test_tlds(data, expected):
assert linkify(data) == expected


def test_escaping():
assert linkify("< unrelated") == "&lt; unrelated"
@pytest.mark.parametrize(
"data,expected",
[
("< unrelated", "&lt; unrelated"),
("<U \x7f=&#;>", '<u \x7f="&amp;#;"></u>'),
],
)
def test_escaping(data, expected):
assert linkify(data) == expected


def test_nofollow_off():
Expand Down

0 comments on commit c66edfd

Please sign in to comment.