diff --git a/CHANGELOG.md b/CHANGELOG.md index e2915105..f8160914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.2.62 + +- fix throw error on empty files + ## v1.2.61 - fix missing cors origin header when port and crossDomainPort are the same diff --git a/package-lock.json b/package-lock.json index 2fc5a49e..8b10fb8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rammerhead", - "version": "1.2.61", + "version": "1.2.62", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rammerhead", - "version": "1.2.61", + "version": "1.2.62", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index a0758f60..5b01623c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rammerhead", - "version": "1.2.61", + "version": "1.2.62", "description": "User friendly web proxy powered by testcafe-hammerhead", "main": "src/index.js", "scripts": { diff --git a/src/classes/RammerheadJSFileCache.js b/src/classes/RammerheadJSFileCache.js index 4d2f93ea..c65ee9f8 100644 --- a/src/classes/RammerheadJSFileCache.js +++ b/src/classes/RammerheadJSFileCache.js @@ -36,7 +36,7 @@ class RammerheadJSFileCache { this.lruMarker = new LRUCache({ max: maxItems, maxSize: jsCacheSize, - sizeCalculation: n => n, + sizeCalculation: n => n || 1, dispose(_, key) { fs.unlinkSync(path.join(diskJsCachePath, key)); } @@ -55,6 +55,11 @@ class RammerheadJSFileCache { initFileList.sort((a, b) => a.size - b.size); for (const file of initFileList) { + if (!file.size) { + // writing probably got interrupted. so we delete the corrupted file + fs.unlinkSync(path.join(diskJsCachePath, file.key)); + continue; + } this.lruMarker.set(file.key, file.size, { noDisposeOnSet: true }); diff --git a/src/classes/RammerheadJSMemCache.js b/src/classes/RammerheadJSMemCache.js index da2da6f3..d9692805 100644 --- a/src/classes/RammerheadJSMemCache.js +++ b/src/classes/RammerheadJSMemCache.js @@ -4,7 +4,7 @@ class RammerheadJSMemCache { constructor(jsCacheSize) { this.lru = new LRUCache({ maxSize: jsCacheSize, - sizeCalculation: n => n.length + sizeCalculation: n => n.length || 1 }); } get(key) { diff --git a/src/util/addJSDiskCache.js b/src/util/addJSDiskCache.js index afc07f88..64fda053 100644 --- a/src/util/addJSDiskCache.js +++ b/src/util/addJSDiskCache.js @@ -15,7 +15,10 @@ module.exports = async function (jsCache) { const md5 = (data) => crypto.createHash('md5').update(data).digest('hex'); cacheGet = async (key) => await jsCache.get(md5(key)); - cacheSet = async (key, value) => await jsCache.set(md5(key), value); + cacheSet = async (key, value) => { + if (!value) return; + await jsCache.set(md5(key), value); + } }; // patch ScriptResourceProcessor