Skip to content

Commit c8fd638

Browse files
committed
Fix validation schema accepting invalid values when instanceof is used
1 parent 14e55e3 commit c8fd638

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/WebpackOptionsValidationError.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ WebpackOptionsValidationError.formatValidationError = function formatValidationE
7575
}
7676
return dataPath + " should be " + err.params.type + ":\n" +
7777
getSchemaPartText(err.parentSchema);
78+
case "instanceof":
79+
return dataPath + " should be an instance of " + getSchemaPartText(err.parentSchema) + ".";
7880
case "required":
7981
var missingProperty = err.params.missingProperty.replace(/^\./, "");
8082
return dataPath + " misses the property '" + missingProperty + "'.\n" +

lib/validateWebpackOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var ajv = new Ajv({
99
allErrors: true,
1010
verbose: true
1111
});
12+
require('ajv-keywords')(ajv);
1213
var validate = ajv.compile(webpackOptionsSchema);
1314

1415
function validateWebpackOptions(options) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"acorn": "^4.0.3",
88
"ajv": "^4.7.0",
9+
"ajv-keywords": "^1.1.1",
910
"async": "^2.1.2",
1011
"enhanced-resolve": "^2.2.0",
1112
"interpret": "^1.0.0",

test/Validation.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ describe("Validation", function() {
3333
" object { <key>: string | [string] } | string | [string]",
3434
" The entry point(s) of the compilation."
3535
]
36+
}, {
37+
name: "invalid instanceof",
38+
config: {
39+
entry: "a",
40+
module: {
41+
exprContextRegExp: 1337
42+
}
43+
},
44+
message: [
45+
" - configuration.module.exprContextRegExp should be an instance of RegExp.",
46+
]
3647
}, {
3748
name: "multiple errors",
3849
config: {

0 commit comments

Comments
 (0)