Skip to content

Commit

Permalink
fix handling of config values that start with . or .. but are not act…
Browse files Browse the repository at this point in the history
…ually relative paths; e.g. ".foo" or "..bar" (#2065)

Co-authored-by: Brian Koehler <[email protected]>
  • Loading branch information
koehlerb and Brian Koehler authored Sep 20, 2020
1 parent c6107af commit 6369f0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit 6369f0b

Please sign in to comment.