From 0c1ab3b39042680d805d33a9d8d4c1f4dcee4974 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 6 Oct 2021 02:25:59 +0200 Subject: [PATCH] gfdg --- files/helpers/sanitize.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 33b78acd8..6576aa6be 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -77,7 +77,7 @@ no_images = ['b', ] _allowed_attributes = { - '*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name'] + '*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name', 'direction'] } _allowed_protocols = [ @@ -91,31 +91,6 @@ _allowed_styles =[ 'transform' ] -# filter to make all links show domain on hover - -def a_modify(attrs, whatever): - - raw_url=attrs.get((None, "href"), None) - if raw_url: - parsed_url = urlparse(raw_url) - - domain = parsed_url.netloc - attrs[(None, "target")] = "_blank" - if domain and not domain.endswith(domain): - attrs[(None, "rel")] = "nofollow noopener noreferrer" - - new_url = ParseResult(scheme="https", - netloc=parsed_url.netloc, - path=parsed_url.path, - params=parsed_url.params, - query=parsed_url.query, - fragment=parsed_url.fragment) - - attrs[(None, "href")] = urlunparse(new_url) - - return attrs - - def sanitize(sanitized, noimages=False): sanitized = sanitized.replace("\ufeff", "").replace("m.youtube.com", "youtube.com") @@ -131,7 +106,6 @@ def sanitize(sanitized, noimages=False): filters=[partial(LinkifyFilter, skip_tags=["pre"], parse_email=False, - callbacks=[a_modify] ) ] ).clean(sanitized) @@ -143,7 +117,6 @@ def sanitize(sanitized, noimages=False): filters=[partial(LinkifyFilter, skip_tags=["pre"], parse_email=False, - callbacks=[a_modify] ) ] ).clean(sanitized) @@ -161,7 +134,6 @@ def sanitize(sanitized, noimages=False): tag["style"] = "max-height: 100px; max-width: 100%;" tag["class"] = "in-comment-image rounded-sm my-2" tag["loading"] = "lazy" - tag["data-src"] = tag["src"] link = soup.new_tag("a") link["href"] = tag["src"] @@ -172,13 +144,14 @@ def sanitize(sanitized, noimages=False): link["data-bs-toggle"] = "modal" link["data-bs-target"] = "#expandImageModal" - tag["src"] = "" - tag.wrap(link) #disguised link preventer for tag in soup.find_all("a"): + tag["target"] = "_blank" + if site not in tag["href"]: tag["rel"] = "nofollow noopener noreferrer" + if re.match("https?://\S+", str(tag.string)): try: tag.string = tag["href"]