Skip to content

Commit

Permalink
Always return cloned data
Browse files Browse the repository at this point in the history
  • Loading branch information
philbooth committed Sep 27, 2016
1 parent dce2cc4 commit c1086b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/convict.js
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs');
const validator = require('validator');
const moment = require('moment');
const minimist = require('minimist');
const cloneDeep = require('lodash/cloneDeep');

function assert(assertion, err_msg) {
if (!assertion) {
Expand Down Expand Up @@ -243,7 +244,6 @@ function addDefaultValues(schema, c, instance) {
}

function isObj(o) { return (typeof o === 'object' && o !== null); }
function isRegExp(r) { return Object.prototype.toString.call(r) === '[object RegExp]'; }

function overlay(from, to, schema) {
Object.keys(from).forEach(function(k) {
Expand Down Expand Up @@ -352,7 +352,7 @@ var convict = function convict(def) {
* Exports all the properties (that is the keys and their current values) as JSON
*/
getProperties: function() {
return this._instance;
return cloneDeep(this._instance);
},
root: deprecate.function(function() {
return this.getProperties();
Expand Down Expand Up @@ -389,9 +389,8 @@ var convict = function convict(def) {
*/
get: function(path) {
var o = walk(this._instance, path);
if (isRegExp(o)) return o;
return typeof o !== 'undefined' ?
JSON.parse(JSON.stringify(o)) :
cloneDeep(o) :
void 0;
},

Expand All @@ -404,9 +403,8 @@ var convict = function convict(def) {
// FOO.properties.BAR.properties.BAZ.default
path = (path.split('.').join('.properties.')) + '.default';
var o = walk(this._schema.properties, path);
if (isRegExp(o)) return o;
return typeof o !== 'undefined' ?
JSON.parse(JSON.stringify(o)) :
cloneDeep(o) :
void 0;
},

Expand Down
5 changes: 5 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"depd": "1.1.0",
"json5": "0.5.0",
"lodash": "4.16.2",
"minimist": "1.2.0",
"moment": "2.12.0",
"validator": "4.6.1"
Expand Down

0 comments on commit c1086b5

Please sign in to comment.