Ensure paths with newlines are walkable.

This commit is contained in:
John-David Dalton
2015-08-17 23:56:27 -07:00
parent 1a9069e80a
commit e7bdd4a624
2 changed files with 12 additions and 12 deletions

View File

@@ -89,9 +89,9 @@
reInterpolate = /<%=([\s\S]+?)%>/g; reInterpolate = /<%=([\s\S]+?)%>/g;
/** Used to match property names within property paths. */ /** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
reIsPlainProp = /^\w*$/, 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). * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).

View File

@@ -12989,15 +12989,15 @@
}); });
test('`_.' + methodName + '` should handle complex paths', 2, function() { 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 = [ var paths = [
'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][e].f', 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
['a', '-1.23', '["b"]', 'c', "['d']", 'e', 'f'] ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
]; ];
_.each(paths, function(path) { _.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() { 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 = [ var paths = [
'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][e].f', 'a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g',
['a', '-1.23', '["b"]', 'c', "['d']", 'e', 'f'] ['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']
]; ];
_.each(paths, function(path) { _.each(paths, function(path) {
func(object, path, 7); func(object, path, 10);
strictEqual(object.a[-1.23]['["b"]'].c["['d']"].e.f, 7); strictEqual(object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g, 10);
object.a[-1.23]['["b"]'].c["['d']"].e.f = 6; object.a[-1.23]['["b"]'].c["['d']"]['\ne\n'].f.g = 8;
}); });
}); });