Ensure path a property name is teated as a key before a path in _.get and _.set.

This commit is contained in:
jdalton
2015-04-03 12:36:31 -05:00
parent adc687f0a0
commit 219d4688e4
2 changed files with 17 additions and 0 deletions

View File

@@ -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,

View File

@@ -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);