Skip to content

Commit ffc548e

Browse files
authored
Merge pull request #261 from webpack/bugfix/parse-crash
validate arguments to resolve and use callback for errors
2 parents 0f51a8c + a2d2b4c commit ffc548e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Resolver.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ class Resolver {
257257
* @returns {void}
258258
*/
259259
resolve(context, path, request, resolveContext, callback) {
260+
if (!context || typeof context !== "object")
261+
return callback(new Error("context argument is not an object"));
262+
if (typeof path !== "string")
263+
return callback(new Error("path argument is not a string"));
264+
if (typeof request !== "string")
265+
return callback(new Error("path argument is not a string"));
266+
if (!resolveContext)
267+
return callback(new Error("resolveContext argument is not set"));
268+
260269
const obj = {
261270
context: context,
262271
path: path,

test/resolve.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,25 @@ describe("resolve", function () {
294294
done();
295295
});
296296
});
297+
298+
it("should not crash when passing undefined as path", done => {
299+
resolve(fixtures, undefined, err => {
300+
err.should.be.instanceof(Error);
301+
done();
302+
});
303+
});
304+
305+
it("should not crash when passing undefined as context", done => {
306+
resolve({}, undefined, "./test/resolve.js", err => {
307+
err.should.be.instanceof(Error);
308+
done();
309+
});
310+
});
311+
312+
it("should not crash when passing undefined everywere", done => {
313+
resolve(undefined, undefined, undefined, undefined, err => {
314+
err.should.be.instanceof(Error);
315+
done();
316+
});
317+
});
297318
});

0 commit comments

Comments
 (0)