mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Ensure paths with newlines are walkable.
This commit is contained in:
@@ -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).
|
||||
|
||||
20
test/test.js
20
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;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user