Skip to content

Commit

Permalink
Add allow-list for #3399, update URL
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Oct 1, 2024
1 parent 3840870 commit 6fe3645
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/TemplateMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,21 @@ ${permalinks[page.outputPath]
page.data.eleventyAllowMissingExtension
) {
// do nothing (also serverless)
} else if (
[
"/_redirects", // Netlify specific
"/.htaccess", // Apache
].some((url) => page.url.endsWith(url))
) {
// do nothing
} else {
if (TemplatePath.getExtension(page.outputPath) === "") {
let e =
new Error(`The template at '${page.inputPath}' attempted to write to '${page.outputPath}'${page.data.permalink ? ` (via \`permalink\` value: '${page.data.permalink}')` : ""}, which is a target on the file system that does not include a file extension.
You *probably* want to add a file extension to your permalink so that hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name.
Learn more: https://www.zachleat.com/web/trailing-slash/
Learn more: https://v3.11ty.dev/docs/permalinks/#trailing-slashes
This is usually but not *always* an error so if you’d like to disable this error message, add \`eleventyAllowMissingExtension: true\` somewhere in the data cascade for this template or use \`eleventyConfig.configureErrorReporting({ allowMissingExtensions: true });\` to disable this feature globally.`);
e.skipOriginalStack = true;
Expand Down
16 changes: 15 additions & 1 deletion test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ test("Truthy outputPath without a file extension now throws an error, issue #339
You *probably* want to add a file extension to your permalink so that hosts will know how to correctly serve this file to web browsers. Without a file extension, this file may not be reliably deployed without additional hosting configuration (it won’t have a mime type) and may also cause local development issues if you later attempt to write to a subdirectory of the same name.
Learn more: https://www.zachleat.com/web/trailing-slash/
Learn more: https://v3.11ty.dev/docs/permalinks/#trailing-slashes
This is usually but not *always* an error so if you’d like to disable this error message, add \`eleventyAllowMissingExtension: true\` somewhere in the data cascade for this template or use \`eleventyConfig.configureErrorReporting({ allowMissingExtensions: true });\` to disable this feature globally.`
});
Expand All @@ -1568,6 +1568,20 @@ test("Truthy outputPath without a file extension can be ignored, issue #3399", a
t.is(results[0].url, "/foo");
});


test("Allow list for some file types without a file extension, issue #3399", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: function (eleventyConfig) {
eleventyConfig.addTemplate("index.html", "", { permalink: "/test/_redirects" })
},
});
elev.disableLogger();

let results = await elev.toJSON();
t.is(results.length, 1);
t.is(results[0].url, "/test/_redirects");
});

test("Truthy outputPath without a file extension error message is disabled, issue #3399", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: function (eleventyConfig) {
Expand Down

0 comments on commit 6fe3645

Please sign in to comment.