Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disallow non-string configPath overrides #130

Merged
merged 2 commits into from Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.js
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
@@ -0,0 +1,5 @@
var path = require('path');

module.exports = {
myappfile: {},
};
15 changes: 15 additions & 0 deletions test/index.js
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