From 44d39c4c635a2c4970e72616d76bb1c6834a8358 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 15 Mar 2024 20:30:18 -0700 Subject: [PATCH 1/2] fix: Disallow non-string configPath overrides --- index.js | 4 +++- .../override-config-path-non-string.js | 5 +++++ test/index.js | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/configfiles/override-config-path-non-string.js diff --git a/index.js b/index.js index a0b60c7..870c576 100644 --- a/index.js +++ b/index.js @@ -158,7 +158,9 @@ Liftoff.prototype.buildEnvironment = function (opts) { var configPathOverride = arrayFind(Object.keys(config), function (key) { var cfg = config[key]; if (Object.prototype.hasOwnProperty.call(cfg, configName)) { - return cfg[configName]; + if (typeof cfg[configName] === "string") { + return cfg[configName]; + } } }); diff --git a/test/fixtures/configfiles/override-config-path-non-string.js b/test/fixtures/configfiles/override-config-path-non-string.js new file mode 100644 index 0000000..7daafb5 --- /dev/null +++ b/test/fixtures/configfiles/override-config-path-non-string.js @@ -0,0 +1,5 @@ +var path = require('path'); + +module.exports = { + myappfile: {}, +}; diff --git a/test/index.js b/test/index.js index 9b26e01..45d120b 100644 --- a/test/index.js +++ b/test/index.js @@ -601,6 +601,21 @@ describe('Liftoff', function () { }); }); + it('ignores non-string configPath if the configName key exists in the config', function (done) { + var app = new Liftoff({ + name: 'myapp', + configFiles: { + 'override-config-path-non-string': [ + { path: 'test/fixtures/configfiles', extensions: ['.js'] } + ], + }, + }); + app.prepare({}, function (env) { + expect(env.configPath).toMatch(null); + done(); + }); + }); + it('should use dirname of configPath if no cwd is specified', function (done) { var app = new Liftoff({ name: 'myapp', From 74cf3dc8cf790ed05c73b5c74e8b6de41ec329f6 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 15 Mar 2024 20:35:39 -0700 Subject: [PATCH 2/2] fixes --- index.js | 4 +++- test/index.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 870c576..4a0dfa6 100644 --- a/index.js +++ b/index.js @@ -119,7 +119,9 @@ Liftoff.prototype.buildEnvironment = function (opts) { // resolve something like `{ gulpfile: "./abc.xyz" }` to the absolute path // based on the path of the configFile if (Object.prototype.hasOwnProperty.call(configFile, configName)) { - configFile[configName] = path.resolve(path.dirname(configFilePath), configFile[configName]); + if (typeof configFile[configName] === 'string') { + configFile[configName] = path.resolve(path.dirname(configFilePath), configFile[configName]); + } } visited[configFilePath] = true; diff --git a/test/index.js b/test/index.js index 45d120b..07726d1 100644 --- a/test/index.js +++ b/test/index.js @@ -611,7 +611,7 @@ describe('Liftoff', function () { }, }); app.prepare({}, function (env) { - expect(env.configPath).toMatch(null); + expect(env.configPath).toEqual(null); done(); }); });