mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 04:51:11 +00:00
Python formatting
This commit is contained in:
parent
1f6ecc39ac
commit
cae7191a2b
2 changed files with 3 additions and 8 deletions
|
@ -22,9 +22,7 @@ class InputHtmlParser(HTMLParser): # pylint: disable=abstract-method
|
||||||
"ol",
|
"ol",
|
||||||
"li",
|
"li",
|
||||||
]
|
]
|
||||||
self.allowed_attrs = [
|
self.allowed_attrs = ["href", "rel", "src", "alt"]
|
||||||
"href", "rel", "src", "alt"
|
|
||||||
]
|
|
||||||
self.tag_stack = []
|
self.tag_stack = []
|
||||||
self.output = []
|
self.output = []
|
||||||
# if the html appears invalid, we just won't allow any at all
|
# if the html appears invalid, we just won't allow any at all
|
||||||
|
@ -36,7 +34,7 @@ class InputHtmlParser(HTMLParser): # pylint: disable=abstract-method
|
||||||
allowed_attrs = " ".join(
|
allowed_attrs = " ".join(
|
||||||
f'{a}="{v}"' for a, v in attrs if a in self.allowed_attrs
|
f'{a}="{v}"' for a, v in attrs if a in self.allowed_attrs
|
||||||
)
|
)
|
||||||
reconstructed = f'<{tag}'
|
reconstructed = f"<{tag}"
|
||||||
if allowed_attrs:
|
if allowed_attrs:
|
||||||
reconstructed += " " + allowed_attrs
|
reconstructed += " " + allowed_attrs
|
||||||
reconstructed += ">"
|
reconstructed += ">"
|
||||||
|
|
|
@ -37,10 +37,7 @@ class Sanitizer(TestCase):
|
||||||
parser = InputHtmlParser()
|
parser = InputHtmlParser()
|
||||||
parser.feed(input_text)
|
parser.feed(input_text)
|
||||||
output = parser.get_output()
|
output = parser.get_output()
|
||||||
self.assertEqual(
|
self.assertEqual(output, '<a href="fish.com">yes </a> <i>html</i>')
|
||||||
output,
|
|
||||||
'<a href="fish.com">yes </a> <i>html</i>'
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_invalid_html(self):
|
def test_invalid_html(self):
|
||||||
"""remove all html when the html is malformed"""
|
"""remove all html when the html is malformed"""
|
||||||
|
|
Loading…
Reference in a new issue