diff --git a/lodash.js b/lodash.js index 524dd5ed3..41727db4c 100644 --- a/lodash.js +++ b/lodash.js @@ -89,9 +89,9 @@ reInterpolate = /<%=([\s\S]+?)%>/g; /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, - rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g; + rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g; /** * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). diff --git a/test/test.js b/test/test.js index 5ce01ffbc..d4b33ac2b 100644 --- a/test/test.js +++ b/test/test.js @@ -12989,15 +12989,15 @@ }); test('`_.' + methodName + '` should handle complex paths', 2, function() { - var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { 'e': { 'f': 6 } } } } } } }; + var object = { 'a': { '-1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } }; var paths = [ - 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][e].f', - ['a', '-1.23', '["b"]', 'c', "['d']", 'e', 'f'] + 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g', + ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g'] ]; _.each(paths, function(path) { - strictEqual(func(object, path), 6); + strictEqual(func(object, path), 8); }); }); @@ -13536,17 +13536,17 @@ }); test('`_.' + methodName + '` should handle complex paths', 2, function() { - var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { 'e': { 'f': 6 } } } } } } }; + var object = { 'a': { '1.23': { '["b"]': { 'c': { "['d']": { '\ne\n': { 'f': { 'g': 8 } } } } } } } }; var paths = [ - 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][e].f', - ['a', '-1.23', '["b"]', 'c', "['d']", 'e', 'f'] + 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g', + ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g'] ]; _.each(paths, function(path) { - func(object, path, 7); - strictEqual(object.a[-1.23]['["b"]'].c["['d']"].e.f, 7); - object.a[-1.23]['["b"]'].c["['d']"].e.f = 6; + func(object, path, 10); + strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, 10); + object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = 8; }); });