From 0177773b65c753141c55456219c35f43dfcc9008 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 3 Nov 2024 15:19:20 +0100 Subject: [PATCH] [FIX] match all occurrences of static/attach If a markup element contains more than one {static} or {attach} value, only the last one was replaced. Simplify the regex to match every occurrence Fixes getpelican/pelican#3419 --- pelican/contents.py | 4 +--- pelican/tests/test_contents.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 0769f875..141e8696 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -372,9 +372,7 @@ class Content: def _get_intrasite_link_regex(self) -> re.Pattern: intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"] regex = rf""" - (?P<[^\>]+ # match tag with all url-value attributes - (?:href|src|poster|data|cite|formaction|action|content)\s*=\s*) - + (?P(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*) (?P["\']) # require value to be quoted (?P{intrasite_link_regex}(?P.*?)) # the url value (?P=quote)""" diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 06d1a690..b1548558 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -519,6 +519,9 @@ class TestPage(TestBase): "images/poster.jpg": Static( "", settings=args["settings"], source_path="images/poster.jpg" ), + "images/placeholder.jpg": Static( + "", settings=args["settings"], source_path="images/placeholder.jpg" + ), } args["context"]["generated_content"] = { "article.rst": Article( @@ -547,6 +550,16 @@ class TestPage(TestBase): content, '' ) + # Image with two links + args["content"] = ( + '' + ) + content = Page(**args).get_content("http://cool.site") + self.assertEqual( + content, + '', + ) + # Image link will go to static args["content"] = '' content = Page(**args).get_content("http://cool.site")