diff --git a/lib/convict.js b/lib/convict.js index b5313fb0..89b19f43 100644 --- a/lib/convict.js +++ b/lib/convict.js @@ -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 = []; @@ -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; } } @@ -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 = {}; @@ -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) { diff --git a/test/cases/nested_dotpath.js b/test/cases/nested_dotpath.js new file mode 100644 index 00000000..e6124efe --- /dev/null +++ b/test/cases/nested_dotpath.js @@ -0,0 +1,5 @@ +'use strict'; + +exports.conf = { + dynamic: { format: Object, default: null } +}; diff --git a/test/cases/nested_dotpath.json b/test/cases/nested_dotpath.json new file mode 100644 index 00000000..8b94b4bb --- /dev/null +++ b/test/cases/nested_dotpath.json @@ -0,0 +1,5 @@ +{ + "dynamic": { + "dot.path": {} + } +} diff --git a/test/cases/nested_dotpath.out b/test/cases/nested_dotpath.out new file mode 100644 index 00000000..8b94b4bb --- /dev/null +++ b/test/cases/nested_dotpath.out @@ -0,0 +1,5 @@ +{ + "dynamic": { + "dot.path": {} + } +}