Skip to content

Commit 4918a10

Browse files
authored
Added support for quoted external CSS URLs in privacy plugin (#7651)
1 parent 7dc96f1 commit 4918a10

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

material/plugins/privacy/plugin.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def on_config(self, config):
6464
# Initialize collections of external assets
6565
self.assets = Files([])
6666
self.assets_expr_map = {
67-
".css": r"url\((\s*http?[^)]+)\)",
68-
".js": r"[\"'](http[^\"']+\.(?:css|js(?:on)?))[\"']",
67+
".css": r"url\(\s*([\"']?)(?P<url>http?[^)'\"]+)\1\s*\)",
68+
".js": r"[\"'](?P<url>http[^\"']+\.(?:css|js(?:on)?))[\"']",
6969
**self.config.assets_expr_map
7070
}
7171

@@ -271,7 +271,8 @@ def _parse_media(self, initiator: File) -> list[URL]:
271271
# Find and extract all external asset URLs
272272
expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M)
273273
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
274-
return [urlparse(url) for url in re.findall(expr, f.read())]
274+
results = re.finditer(expr, f.read())
275+
return [urlparse(result.group("url")) for result in results]
275276

276277
# Parse template or page HTML and find all external links that need to be
277278
# replaced. Many of the assets should already be downloaded earlier, i.e.,

src/plugins/privacy/plugin.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def on_config(self, config):
6464
# Initialize collections of external assets
6565
self.assets = Files([])
6666
self.assets_expr_map = {
67-
".css": r"url\((\s*http?[^)]+)\)",
68-
".js": r"[\"'](http[^\"']+\.(?:css|js(?:on)?))[\"']",
67+
".css": r"url\(\s*([\"']?)(?P<url>http?[^)'\"]+)\1\s*\)",
68+
".js": r"[\"'](?P<url>http[^\"']+\.(?:css|js(?:on)?))[\"']",
6969
**self.config.assets_expr_map
7070
}
7171

@@ -271,7 +271,8 @@ def _parse_media(self, initiator: File) -> list[URL]:
271271
# Find and extract all external asset URLs
272272
expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M)
273273
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
274-
return [urlparse(url) for url in re.findall(expr, f.read())]
274+
results = re.finditer(expr, f.read())
275+
return [urlparse(result.group("url")) for result in results]
275276

276277
# Parse template or page HTML and find all external links that need to be
277278
# replaced. Many of the assets should already be downloaded earlier, i.e.,

0 commit comments

Comments
 (0)