diff --git a/lodash.src.js b/lodash.src.js index 6dcfa43d1..b11162c84 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -88,7 +88,7 @@ reInterpolate = /<%=([\s\S]+?)%>/g; /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/, + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g; diff --git a/test/test.js b/test/test.js index 0680b6e47..59f9e3575 100644 --- a/test/test.js +++ b/test/test.js @@ -13249,6 +13249,11 @@ strictEqual(func(object, ['a', 'b', 'c']), 3); }); + test('`_.' + methodName + '` should ignore empty brackets', 1, function() { + var object = { 'a': 1 }; + strictEqual(func(object, 'a[]'), 1); + }); + test('`_.' + methodName + '` should handle empty paths', 4, function() { _.each([['', ''], [[], ['']]], function(paths) { strictEqual(func({}, paths[0]), undefined); @@ -13712,11 +13717,19 @@ deepEqual(object, { 'a,b,c': 4, 'a': { 'b': { 'c': 3 } } }); }); + test('should ignore empty brackets', 1, function() { + var object = {}; + _.set(object, 'a[]', 1); + deepEqual(object, { 'a': 1 }); + }); + test('should handle empty paths', 4, function() { _.each([['', ''], [[], ['']]], function(paths, index) { var object = {}; + _.set(object, paths[0], 1); deepEqual(object, index ? {} : { '': 1 }); + _.set(object, paths[1], 2); deepEqual(object, { '': 2 }); });