diff --git a/lodash.js b/lodash.js index eb990c35c..43b73d336 100644 --- a/lodash.js +++ b/lodash.js @@ -3696,20 +3696,19 @@ nested = object; while (nested != null && ++index < length) { - var key = toKey(path[index]); - if (isObject(nested)) { - var newValue = value; - if (index != lastIndex) { - var objValue = nested[key]; - newValue = customizer ? customizer(objValue, key, nested) : undefined; - if (newValue === undefined) { - newValue = objValue == null - ? (isIndex(path[index + 1]) ? [] : {}) - : objValue; - } + var key = toKey(path[index]), + newValue = value; + + if (index != lastIndex) { + var objValue = nested[key]; + newValue = customizer ? customizer(objValue, key, nested) : undefined; + if (newValue === undefined) { + newValue = isObject(objValue) + ? objValue + : (isIndex(path[index + 1]) ? [] : {}); } - assignValue(nested, key, newValue); } + assignValue(nested, key, newValue); nested = nested[key]; } return object; diff --git a/test/test.js b/test/test.js index 585199b54..0521663ec 100644 --- a/test/test.js +++ b/test/test.js @@ -19865,41 +19865,15 @@ assert.deepEqual(actual, expected); }); - QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) { - assert.expect(4); - - var object = { 'a': '' }, - paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']]; - - lodashStable.each(paths, function(path) { - func(0, path, updater); - assert.strictEqual(0..a, value); - delete numberProto.a; - }); - - lodashStable.each(['a.replace.b', ['a', 'replace', 'b']], function(path) { - func(object, path, updater); - assert.strictEqual(stringProto.replace.b, value); - delete stringProto.replace.b; - }); - }); - - QUnit.test('`_.' + methodName + '` should not error on paths over primitives in strict mode', function(assert) { - 'use strict'; - + QUnit.test('`_.' + methodName + '` should overwrite primitives in the path', function(assert) { assert.expect(2); - - lodashStable.each(['a', 'a.a.a'], function(path) { - numberProto.a = oldValue; - try { - func(0, path, updater); - assert.strictEqual(0..a, oldValue); - } catch (e) { - assert.ok(false, e.message); - } - }); - - delete numberProto.a; + + lodashStable.each(['a.b', ['a', 'b']], function(path) { + var object = { 'a': '' }; + + func(object, path, updater); + assert.deepEqual(object, { 'a': { 'b': 2 } }); + });; }); QUnit.test('`_.' + methodName + '` should not create an array for missing non-index property names that start with numbers', function(assert) {