mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Ensure fp.update does not convert end of path to an object. [closes #2271]
This commit is contained in:
@@ -235,6 +235,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = path.length,
|
length = path.length,
|
||||||
|
lastIndex = length - 1,
|
||||||
result = clone(Object(object)),
|
result = clone(Object(object)),
|
||||||
nested = result;
|
nested = result;
|
||||||
|
|
||||||
@@ -243,7 +244,7 @@ function baseConvert(util, name, func, options) {
|
|||||||
value = nested[key];
|
value = nested[key];
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
nested[key] = clone(Object(value));
|
nested[path[index]] = clone(index == lastIndex ? value : Object(value));
|
||||||
}
|
}
|
||||||
nested = nested[key];
|
nested = nested[key];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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');
|
QUnit.module('padChars methods');
|
||||||
|
|
||||||
_.each(['padChars', 'padCharsStart', 'padCharsEnd'], function(methodName) {
|
_.each(['padChars', 'padCharsStart', 'padCharsEnd'], function(methodName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user