diff --git a/core/models/config.js b/core/models/config.js index 3347b44..8120fd8 100644 --- a/core/models/config.js +++ b/core/models/config.js @@ -340,7 +340,7 @@ class Config { ...opts, }; - const { error } = optionsSchema.validate(opts); + const { error, value } = optionsSchema.validate(opts, { stripUnknown: true }); if (error) { const details = (error?.details || []) .flatMap((detail) => [detail.message, detail.context.message]) @@ -349,7 +349,7 @@ class Config { throw new Error(`Config schema validation failed: ${details}`); } - return new Config(opts); + return new Config(value); } /** @@ -384,7 +384,7 @@ class Config { ...data, }; - const { error } = optionsSchema.validate(opts); + const { error, value } = optionsSchema.validate(opts, { stripUnknown: true }); if (error) { const details = (error?.details || []) .flatMap((detail) => [detail.message, detail.context.message]) @@ -393,7 +393,7 @@ class Config { throw new Error(`Config file ${configFilePath} contains errors :\n${details}`); } - return new Config(opts); + return new Config(value); } /** diff --git a/core/models/config.spec.js b/core/models/config.spec.js index eb89ad4..44d1dcd 100644 --- a/core/models/config.spec.js +++ b/core/models/config.spec.js @@ -216,4 +216,19 @@ css_custom: styles.css const config = Config.get('../config.yml'); expect(config.canCssCustom()).toBe(true); }); + + it('should ignore unknown options', () => { + const configContent = ` +${minimalConfigContent} +unknown: true + `; + + mockReadConfigFile.mockImplementationOnce(() => configContent); + const config = Config.get('../config.yml'); + expect(config.opts).not.toEqual( + expect.objectContaining({ + unknown: true, + }), + ); + }); });