From 7dc96f1e13fbdf96eec3cba01f1e041b03d182f1 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Wed, 30 Oct 2024 13:54:31 +0100 Subject: [PATCH] Added support for downloading external images in SVG for privacy plugin (#7650) --- material/plugins/privacy/plugin.py | 9 ++++++++- src/plugins/privacy/plugin.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/material/plugins/privacy/plugin.py b/material/plugins/privacy/plugin.py index d99fa782e6b..3ae8a5bb6ca 100644 --- a/material/plugins/privacy/plugin.py +++ b/material/plugins/privacy/plugin.py @@ -313,12 +313,19 @@ def replace(match: Match): file = self._queue(url, config) el.set("src", resolve(file)) + # Handle external image in SVG + if el.tag == "image": + url = urlparse(el.get("href")) + if not self._is_excluded(url, initiator): + file = self._queue(url, config) + el.set("href", resolve(file)) + # Return element as string return self._print(el) # Find and replace all external asset URLs in current page return re.sub( - r"<(?:(?:a|link)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>", + r"<(?:(?:a|link|image)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>", replace, output, flags = re.I | re.M ) diff --git a/src/plugins/privacy/plugin.py b/src/plugins/privacy/plugin.py index d99fa782e6b..3ae8a5bb6ca 100644 --- a/src/plugins/privacy/plugin.py +++ b/src/plugins/privacy/plugin.py @@ -313,12 +313,19 @@ def replace(match: Match): file = self._queue(url, config) el.set("src", resolve(file)) + # Handle external image in SVG + if el.tag == "image": + url = urlparse(el.get("href")) + if not self._is_excluded(url, initiator): + file = self._queue(url, config) + el.set("href", resolve(file)) + # Return element as string return self._print(el) # Find and replace all external asset URLs in current page return re.sub( - r"<(?:(?:a|link)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>", + r"<(?:(?:a|link|image)[^>]+href|(?:script|img)[^>]+src)=['\"]?http[^>]+>", replace, output, flags = re.I | re.M )