Skip to content

Commit 817343b

Browse files
committed
[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 #3419
1 parent 0da2530 commit 817343b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

pelican/contents.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ def _find_path(path: str) -> Optional[Content]:
372372
def _get_intrasite_link_regex(self) -> re.Pattern:
373373
intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"]
374374
regex = rf"""
375-
(?P<markup><[^\>]+ # match tag with all url-value attributes
376-
(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*)
377-
375+
(?P<markup>(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*)
378376
(?P<quote>["\']) # require value to be quoted
379377
(?P<path>{intrasite_link_regex}(?P<value>.*?)) # the url value
380378
(?P=quote)"""

pelican/tests/test_contents.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ def test_intrasite_link_absolute(self):
547547
content, '<img src="http://static.cool.site/images/poster.jpg"/>'
548548
)
549549

550+
# Image with two links
551+
args["content"] = '<img src="{static}/images/placeholder.jpg" data-src="{static}/images/poster.jpg"/>'
552+
content = Page(**args).get_content("http://cool.site")
553+
self.assertEqual(
554+
content, '<img src="http://static.cool.site/images/placeholder.jpg" data-src="http://static.cool.site/images/poster.jpg"/>'
555+
)
556+
550557
# Image link will go to static
551558
args["content"] = '<meta content="{static}/images/poster.jpg"/>'
552559
content = Page(**args).get_content("http://cool.site")

0 commit comments

Comments
 (0)