From 8038130fd71fb0e06133c47f303b03e5b0edf97b Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Fri, 25 Feb 2022 14:15:53 -0600 Subject: [PATCH] Fixes #14 --- package.json | 1 + src/AssetCache.js | 6 ++++++ test/AssetCacheTest.js | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/package.json b/package.json index 8c695a6..5b261c3 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "ava": "^4.0.1" }, "dependencies": { + "@sindresorhus/slugify": "^1.1.2", "debug": "^4.3.3", "flat-cache": "^3.0.4", "node-fetch": "^2.6.7", diff --git a/src/AssetCache.js b/src/AssetCache.js index 9071b42..ddd3ade 100644 --- a/src/AssetCache.js +++ b/src/AssetCache.js @@ -2,6 +2,7 @@ const fs = require("fs"); const fsp = fs.promises; // Node 10+ const path = require("path"); const flatCache = require("flat-cache"); +const slugify = require("@sindresorhus/slugify"); const debug = require("debug")("EleventyCacheAssets"); class AssetCache { @@ -25,6 +26,11 @@ class AssetCache { } set hash(value) { + value = slugify(value, { + preserveLeadingUnderscore: true, + preserveTrailingDash: true, + }); + if(value !== this._hash) { this._cacheLocationDirty = true; } diff --git a/test/AssetCacheTest.js b/test/AssetCacheTest.js index 30582d0..36dc82d 100644 --- a/test/AssetCacheTest.js +++ b/test/AssetCacheTest.js @@ -52,4 +52,11 @@ test("Test a save", async t => { fs.unlinkSync(cachePath); fs.unlinkSync(jsonCachePath); +}); + +test("Cache path should be slugified, issue #14", t => { + let cache = new AssetCache("lksdjflk/jsdf", "/tmp/.cache"); + let cachePath = normalizePath(cache.cachePath); + + t.is(cachePath, "/tmp/.cache/eleventy-fetch-lksdjflk-jsdf"); }); \ No newline at end of file