diff --git a/material/plugins/privacy/plugin.py b/material/plugins/privacy/plugin.py index d99fa782e6b..3b7d9481f6a 100644 --- a/material/plugins/privacy/plugin.py +++ b/material/plugins/privacy/plugin.py @@ -64,8 +64,8 @@ def on_config(self, config): # Initialize collections of external assets self.assets = Files([]) self.assets_expr_map = { - ".css": r"url\((\s*http?[^)]+)\)", - ".js": r"[\"'](http[^\"']+\.(?:css|js(?:on)?))[\"']", + ".css": r"url\(([\"']?)(?P\s*http?[^)'\"]+)\1\)", + ".js": r"[\"'](?Phttp[^\"']+\.(?:css|js(?:on)?))[\"']", **self.config.assets_expr_map } @@ -271,7 +271,8 @@ def _parse_media(self, initiator: File) -> list[URL]: # Find and extract all external asset URLs expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M) with open(initiator.abs_src_path, encoding = "utf-8-sig") as f: - return [urlparse(url) for url in re.findall(expr, f.read())] + results = re.finditer(expr, f.read()) + return [urlparse(result.group("url")) for result in results] # Parse template or page HTML and find all external links that need to be # replaced. Many of the assets should already be downloaded earlier, i.e., diff --git a/src/plugins/privacy/plugin.py b/src/plugins/privacy/plugin.py index d99fa782e6b..3b7d9481f6a 100644 --- a/src/plugins/privacy/plugin.py +++ b/src/plugins/privacy/plugin.py @@ -64,8 +64,8 @@ def on_config(self, config): # Initialize collections of external assets self.assets = Files([]) self.assets_expr_map = { - ".css": r"url\((\s*http?[^)]+)\)", - ".js": r"[\"'](http[^\"']+\.(?:css|js(?:on)?))[\"']", + ".css": r"url\(([\"']?)(?P\s*http?[^)'\"]+)\1\)", + ".js": r"[\"'](?Phttp[^\"']+\.(?:css|js(?:on)?))[\"']", **self.config.assets_expr_map } @@ -271,7 +271,8 @@ def _parse_media(self, initiator: File) -> list[URL]: # Find and extract all external asset URLs expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M) with open(initiator.abs_src_path, encoding = "utf-8-sig") as f: - return [urlparse(url) for url in re.findall(expr, f.read())] + results = re.finditer(expr, f.read()) + return [urlparse(result.group("url")) for result in results] # Parse template or page HTML and find all external links that need to be # replaced. Many of the assets should already be downloaded earlier, i.e.,