diff --git a/lodash.src.js b/lodash.src.js index 250e3470f..d25d362e4 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -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, diff --git a/test/test.js b/test/test.js index c5c181873..b3649dfba 100644 --- a/test/test.js +++ b/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);