From e2c86dac63cbb9d6788dbc2b51e5c328288f08d8 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 22 Apr 2016 08:46:35 -0700 Subject: [PATCH] Ensure `fp.update` does not convert end of `path` to an object. [closes #2271] --- fp/_baseConvert.js | 3 ++- test/test-fp.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fp/_baseConvert.js b/fp/_baseConvert.js index e7e631ce4..1d92da540 100644 --- a/fp/_baseConvert.js +++ b/fp/_baseConvert.js @@ -235,6 +235,7 @@ function baseConvert(util, name, func, options) { var index = -1, length = path.length, + lastIndex = length - 1, result = clone(Object(object)), nested = result; @@ -243,7 +244,7 @@ function baseConvert(util, name, func, options) { value = nested[key]; if (value != null) { - nested[key] = clone(Object(value)); + nested[path[index]] = clone(index == lastIndex ? value : Object(value)); } nested = nested[key]; } diff --git a/test/test-fp.js b/test/test-fp.js index 775d7eed2..739ceed40 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1474,6 +1474,19 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('fp.update'); + + (function() { + QUnit.test('should not convert end of `path` to an object', function(assert) { + assert.expect(1); + + var actual = fp.update('a.b')(_.identity)({ 'a': { 'b': 1 } }); + assert.strictEqual(typeof actual.a.b, 'number'); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('padChars methods'); _.each(['padChars', 'padCharsStart', 'padCharsEnd'], function(methodName) {