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(configuration): Fix handling of config values that start with . or .. but are not relative paths #2065

Merged
merged 1 commit into from
Sep 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/configuration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function init () {
if (process.env[value]) {
value = process.env[value];
}
if (value.indexOf('.') === 0 || value.indexOf('..') === 0) {
if (value.indexOf('./') === 0 || value.indexOf('../') === 0) {
// Make relative paths absolute
value = path.resolve(
path.join(config.util.getEnv('NODE_CONFIG_DIR')),
Expand Down
2 changes: 2 additions & 0 deletions packages/configuration/test/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"port": 3030,
"environment": "NODE_ENV",
"path": "../something",
"notDotPath": ".dot",
"notDotDotPath": "..dotdot",
"pathFromEnv": "PATH_ENV",
"unescaped": "\\NODE_ENV",
"from": "default",
Expand Down
8 changes: 8 additions & 0 deletions packages/configuration/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ describe('@feathersjs/configuration', () => {
assert.strictEqual(app.get('pathFromEnv'), join(__dirname, 'something'))
);

it('does not normalize values that start with . but are not a relative path', () =>
assert.strictEqual(app.get('notDotPath'), '.dot')
);

it('does not normalize values that start with .. but are not a relative path', () =>
assert.strictEqual(app.get('notDotDotPath'), '..dotdot')
);

it('converts environment variables recursively', () =>
assert.strictEqual(app.get('deeply').nested.env, 'testing')
);
Expand Down