Skip to content

Commit

Permalink
[FIX] match all occurrences of static/attach
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mart-e committed Nov 3, 2024
1 parent 0da2530 commit 817343b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ def _find_path(path: str) -> Optional[Content]:
def _get_intrasite_link_regex(self) -> re.Pattern:
intrasite_link_regex = self.settings["INTRASITE_LINK_REGEX"]
regex = rf"""
(?P<markup><[^\>]+ # match tag with all url-value attributes
(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*)
(?P<markup>(?:href|src|poster|data|cite|formaction|action|content)\s*=\s*)
(?P<quote>["\']) # require value to be quoted
(?P<path>{intrasite_link_regex}(?P<value>.*?)) # the url value
(?P=quote)"""
Expand Down
7 changes: 7 additions & 0 deletions pelican/tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ def test_intrasite_link_absolute(self):
content, '<img src="http://static.cool.site/images/poster.jpg"/>'
)

# Image with two links
args["content"] = '<img src="{static}/images/placeholder.jpg" data-src="{static}/images/poster.jpg"/>'
content = Page(**args).get_content("http://cool.site")
self.assertEqual(
content, '<img src="http://static.cool.site/images/placeholder.jpg" data-src="http://static.cool.site/images/poster.jpg"/>'
)

# Image link will go to static
args["content"] = '<meta content="{static}/images/poster.jpg"/>'
content = Page(**args).get_content("http://cool.site")
Expand Down

0 comments on commit 817343b

Please sign in to comment.