Skip to content

eleventy-img doesn't unescape HTML-escaped image names when reading them from HTML to transform #307

@stuartlangridge

Description

@stuartlangridge

Create a simple eleventy site which uses eleventyImageTransformPlugin:

$ mkdir eleventy-sample
$ cd eleventy-sample/
$ npm init -y
$ npm install @11ty/eleventy @11ty/eleventy-img
$ cat <<__EOF > eleventy.config.js
const { eleventyImageTransformPlugin } = require("@11ty/eleventy-img");

module.exports = function (eleventyConfig) {
        eleventyConfig.addPlugin(eleventyImageTransformPlugin);
};
__EOF
$ echo "Add an image with an ampersand in its filename"
$ convert rose: "rose&rose.jpg"
$ cat <<__EOF >index.html
<!doctype html>
<html><body>
<p>Here's an image, with its name escaped so it's valid HTML, as is right and proper.</p>
<img src="rose&amp;rose.jpg" alt="By any other name">
</body></html>
__EOF
$ npx @11ty/eleventy

... and 11ty-img fails the build:

[11ty] 1. Having trouble writing to "./_site/index.html" from "./index.html" (via EleventyTemplateError)
[11ty] 2. Transform `@11ty/eleventy/html-transformer` encountered an error when transforming ./index.html. (via EleventyTransformError)
[11ty] 3. ENOENT: no such file or directory, stat 'rose&amp;rose.jpg'
[11ty] 

It seems that when eleventyImageTransformPlugin reads filenames from HTML, it doesn't unescape them first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions