From c9bad176fd292358cef5105e4d35ae38808c3ed1 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Wed, 11 Oct 2017 13:53:12 -0500 Subject: [PATCH] Fix #5806, TypeError on ExternalModule hash.update undefined must be coerced to `false` --- lib/ExternalModule.js | 2 +- test/ExternalModule.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index d9d6fbcd4..de1e9db9c 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -120,7 +120,7 @@ class ExternalModule extends Module { updateHash(hash) { hash.update(this.type); hash.update(JSON.stringify(this.request)); - hash.update(JSON.stringify(this.optional)); + hash.update(JSON.stringify(Boolean(this.optional))); super.updateHash(hash); } } diff --git a/test/ExternalModule.test.js b/test/ExternalModule.test.js index 6fd56c6a2..bd7e4bf75 100644 --- a/test/ExternalModule.test.js +++ b/test/ExternalModule.test.js @@ -340,4 +340,32 @@ module.exports = some/request;`; hashedText.should.containEql("12345678"); }); }); + + describe("#updateHash without optional", function() { + let hashedText; + let hash; + beforeEach(function() { + hashedText = ""; + hash = { + update: (text) => { + hashedText += text; + } + }; + // Note no set of `externalModule.optional`, which crashed externals in 3.7.0 + externalModule.id = 12345678; + externalModule.updateHash(hash); + }); + it("updates hash with request", function() { + hashedText.should.containEql("some/request"); + }); + it("updates hash with type", function() { + hashedText.should.containEql("some-type"); + }); + it("updates hash with optional flag", function() { + hashedText.should.containEql("false"); + }); + it("updates hash with module id", function() { + hashedText.should.containEql("12345678"); + }); + }); });