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 dot-paths in dynamic objects #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions lib/convict.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const ALLOWED_OPTION_STRICT = 'strict';
const ALLOWED_OPTION_WARN = 'warn';

function flatten(obj, useProperties) {
let stack = Object.keys(obj);
let stack = Object.keys(obj).map(k => [k]);
let key;

let entries = [];
Expand All @@ -111,9 +111,9 @@ function flatten(obj, useProperties) {
if (useProperties) {
if ('properties' in val) {
val = val.properties;
key = key + '.properties';
key.push('properties');
} else {
entries.push([key, val]);
entries.push([key.join('.'), val]);
continue;
}
}
Expand All @@ -122,12 +122,12 @@ function flatten(obj, useProperties) {
// Don't filter out empty objects
if (subkeys.length > 0) {
subkeys.forEach(function(subkey) {
stack.push(key + '.' + subkey);
stack.push(key.concat([subkey]));
});
continue;
}
}
entries.push([key, val]);
entries.push([key.join('.'), val]);
}

let flattened = {};
Expand Down Expand Up @@ -456,7 +456,7 @@ function loadFile(path) {

function walk(obj, path, initializeMissing) {
if (path) {
let ar = path.split('.');
let ar = Array.isArray(path) ? cloneDeep(path) : path.split('.');
while (ar.length) {
let k = ar.shift();
if (initializeMissing && obj[k] == null) {
Expand Down
5 changes: 5 additions & 0 deletions test/cases/nested_dotpath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

exports.conf = {
dynamic: { format: Object, default: null }
};
5 changes: 5 additions & 0 deletions test/cases/nested_dotpath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dynamic": {
"dot.path": {}
}
}
5 changes: 5 additions & 0 deletions test/cases/nested_dotpath.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dynamic": {
"dot.path": {}
}
}