mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Ensure path a property name is teated as a key before a path in _.get and _.set.
This commit is contained in:
@@ -9951,6 +9951,10 @@
|
||||
if (object == null) {
|
||||
return object;
|
||||
}
|
||||
if (isKey(path) || (path in toObject(object))) {
|
||||
object[path] = value;
|
||||
return object;
|
||||
}
|
||||
path = toPath(path);
|
||||
|
||||
var index = -1,
|
||||
|
||||
13
test/test.js
13
test/test.js
@@ -6003,6 +6003,11 @@
|
||||
strictEqual(_.get(object, 'a.b.c'), 3);
|
||||
});
|
||||
|
||||
test('should get a key before treating it as a path', 1, function() {
|
||||
var object = { 'a.b.c': 3 };
|
||||
strictEqual(_.get(object, 'a.b.c'), 3);
|
||||
});
|
||||
|
||||
test('should return `undefined` when `object` is nullish', 2, function() {
|
||||
strictEqual(_.get(null, 'a'), undefined);
|
||||
strictEqual(_.get(undefined, 'a'), undefined);
|
||||
@@ -12975,6 +12980,14 @@
|
||||
strictEqual(object.a.b.c, 4);
|
||||
});
|
||||
|
||||
test('should set a key before treating it as a path', 2, function() {
|
||||
var object = { 'a.b.c': 3 },
|
||||
actual = _.set(object, 'a.b.c', 4);
|
||||
|
||||
strictEqual(actual, object);
|
||||
deepEqual(object, { 'a.b.c': 4 });
|
||||
});
|
||||
|
||||
test('should create parts of `path` that are missing', 3, function() {
|
||||
var object = {},
|
||||
actual = _.set(object, 'a[1].b.c', 4);
|
||||
|
||||
Reference in New Issue
Block a user