diff --git a/tildes/tests/test_markdown.py b/tildes/tests/test_markdown.py index 2d5b8d4..1ed212e 100644 --- a/tildes/tests/test_markdown.py +++ b/tildes/tests/test_markdown.py @@ -130,14 +130,6 @@ def test_https_link_linkified(): assert '' in processed -def test_bare_domain_linkified(): - """Ensure that a bare domain results in a link.""" - markdown = "I can just write example.com too." - processed = convert_markdown_to_safe_html(markdown) - - assert '' in processed - - def test_link_with_path_linkified(): """Ensure a link with a path results in a link.""" markdown = "So http://example.com/a/b_c_d/e too?" @@ -148,18 +140,10 @@ def test_link_with_path_linkified(): def test_link_with_query_string_linkified(): """Ensure a link with a query string results in a link.""" - markdown = "Also http://example.com?something=true works?" + markdown = "Also http://example.com?something=true&test=yes works?" processed = convert_markdown_to_safe_html(markdown) - assert '' in processed - - -def test_email_address_not_linkified(): - """Ensure that an email address does not get linkified.""" - markdown = "Please contact somebody@example.com about that." - processed = convert_markdown_to_safe_html(markdown) - - assert "' in processed def test_other_protocol_urls_not_linkified(): @@ -170,7 +154,7 @@ def test_other_protocol_urls_not_linkified(): markdown = f"Testing {protocol}://example.com for linking" processed = convert_markdown_to_safe_html(markdown) - assert " tag. -NamespacedAttrDict = Dict[Union[Tuple[Optional[str], str], str], str] - - -def linkify_protocol_whitelist( - attrs: NamespacedAttrDict, new: bool = False -) -> Optional[NamespacedAttrDict]: - """bleach.linkify callback: prevent links to non-whitelisted protocols.""" - # pylint: disable=unused-argument - href = attrs.get((None, "href")) - if not href: - return attrs - - parsed = urlparse(href) - - if parsed.scheme not in PROTOCOL_WHITELIST: - return None - - return attrs - @histogram_timer("markdown_processing") def convert_markdown_to_safe_html(markdown: str) -> str: @@ -444,17 +409,12 @@ def linkify_and_sanitize_html(html: str) -> str: # list of tag names to exclude from linkification linkify_skipped_tags = ["code", "pre"] - bleach_linkifier = partial( - bleach.linkifier.LinkifyFilter, - callbacks=[linkify_protocol_whitelist], - skip_tags=linkify_skipped_tags, - ) tildes_linkifier = partial(LinkifyFilter, skip_tags=linkify_skipped_tags) cleaner = bleach.Cleaner( tags=HTML_TAG_WHITELIST, attributes=HTML_ATTRIBUTE_WHITELIST, protocols=PROTOCOL_WHITELIST, - filters=[bleach_linkifier, tildes_linkifier], + filters=[tildes_linkifier], ) return cleaner.clean(html)