From 8105c761ad3fb0dcee491825e29a74d4a3e0fd70 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 12 Feb 2014 12:31:55 -0600 Subject: [PATCH] [fix] only reverse keys for "get" action to be safe. --- lib/nconf/provider.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/nconf/provider.js b/lib/nconf/provider.js index 5d5bc7b..7dea122 100644 --- a/lib/nconf/provider.js +++ b/lib/nconf/provider.js @@ -507,7 +507,12 @@ Provider.prototype._execute = function (action, syncLength /* [arguments] */) { destructive = ['set', 'clear', 'merge', 'reset'].indexOf(action) !== -1, self = this, response, - mergeObjs = []; + mergeObjs = [], + keys = Object.keys(this.stores); + + if (action === 'get') { + keys = keys.reverse(); + } function runAction (name, next) { var store = self.stores[name]; @@ -522,13 +527,12 @@ Provider.prototype._execute = function (action, syncLength /* [arguments] */) { } if (callback) { - return async.forEach(Object.keys(this.stores).reverse(), runAction, function (err) { + return async.forEach(keys, runAction, function (err) { return err ? callback(err) : callback(); }); } - - Object.keys(this.stores).reverse().forEach(function (name) { + keys.forEach(function (name) { if (typeof response === 'undefined') { var store = self.stores[name];