Skip to content

Commit 3da4f3e

Browse files
authored
Merge pull request #5085 from jbellenger/jbellenger/rawmodule-hash
fix RawModule hashing
2 parents 316d4b9 + 8c9dc14 commit 3da4f3e

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎lib/RawModule.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ module.exports = class RawModule extends Module {
4747
return new RawSource(this.sourceStr);
4848
}
4949

50+
updateHash(hash) {
51+
hash.update(this.sourceStr);
52+
super.updateHash(hash);
53+
}
5054
};

‎test/RawModule.test.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const RawSource = require("webpack-sources").RawSource;
66
const RequestShortener = require("../lib/RequestShortener");
77
const should = require("should");
88
const path = require("path");
9+
const crypto = require("crypto");
910

1011
describe("RawModule", () => {
1112
let myRawModule;
@@ -62,4 +63,18 @@ describe("RawModule", () => {
6263
}
6364
);
6465
});
66+
67+
describe("updateHash", () => {
68+
it("should include sourceStr in its hash", () => {
69+
const hashModule = (module) => {
70+
const hash = crypto.createHash("sha256");
71+
module.updateHash(hash);
72+
return hash.digest("hex");
73+
};
74+
75+
const hashFoo = hashModule(new RawModule("\"foo\""));
76+
const hashBar = hashModule(new RawModule("\"bar\""));
77+
hashFoo.should.not.equal(hashBar);
78+
});
79+
});
6580
});

0 commit comments

Comments
 (0)