Skip to content

Commit 48aedff

Browse files
committed
ensure locally-fetched images are safe. See #4747
1 parent 61e7098 commit 48aedff

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/resources/filters/quarto-post/pdf-images.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ end
2424
-- keyed by {url: mediabagpath}
2525
local resolvedUrls = {}
2626

27+
-- replace invalid tex characters with underscores
28+
local tex_safe_filename = function(filename)
29+
-- return filename
30+
return filename:gsub('[^%w%.%-]', '-')
31+
end
32+
2733
function pdfImages()
2834
return {
2935
-- convert SVG images to PDF when rendering PDFS
@@ -88,14 +94,15 @@ function pdfImages()
8894
local relativePath = image.src:match('http[s]://[%w%.%:]+/(.+)')
8995
if relativePath then
9096
local imgMt, imgContents = pandoc.mediabag.fetch(image.src)
91-
local filename = pandoc.path.filename(relativePath)
97+
local filename = tex_safe_filename(pandoc.path.filename(relativePath))
9298
if imgMt ~= nil then
9399
local existingMt = pandoc.mediabag.lookup(filename)
94100
local counter = 1
95101
while (existingMt) do
96102
local stem, ext = pandoc.path.split_extension(filename)
97103
filename = stem .. counter .. ext
98104
existingMt = pandoc.mediabag.lookup(filename)
105+
counter = counter + 1
99106
end
100107
resolvedUrls[image.src] = filename
101108
pandoc.mediabag.insert(filename, imgMt, imgContents)

0 commit comments

Comments
 (0)