Skip to content

Commit

Permalink
fix: Disallow non-string configPath overrides (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Mar 16, 2024
1 parent 5301335 commit 6bcd381
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,7 +160,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];
}
}
});

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/configfiles/override-config-path-non-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var path = require('path');

module.exports = {
myappfile: {},
};
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).toEqual(null);
done();
});
});

it('should use dirname of configPath if no cwd is specified', function (done) {
var app = new Liftoff({
name: 'myapp',
Expand Down

0 comments on commit 6bcd381

Please sign in to comment.