mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Ensure _.toPath converts array values to strings.
This commit is contained in:
@@ -11480,7 +11480,7 @@
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function toPath(value) {
|
function toPath(value) {
|
||||||
return isArray(value) ? copyArray(value) : stringToPath(value);
|
return isArray(value) ? arrayMap(value, String) : stringToPath(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15653,13 +15653,15 @@
|
|||||||
deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
|
deepEqual(_.toPath('a[0].b.c'), ['a', '0', 'b', 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should shallow clone array path', 2, function() {
|
test('should coerce array elements to strings', 4, function() {
|
||||||
var array = ['a', 'b', 'c'],
|
var array = ['a', 'b', 'c'];
|
||||||
actual = _.toPath(array);
|
|
||||||
|
|
||||||
|
_.each([array, _.map(array, Object)], function(value) {
|
||||||
|
var actual = _.toPath(value);
|
||||||
deepEqual(actual, array);
|
deepEqual(actual, array);
|
||||||
notStrictEqual(actual, array);
|
notStrictEqual(actual, array);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('should handle complex paths', 1, function() {
|
test('should handle complex paths', 1, function() {
|
||||||
var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
|
var actual = _.toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
|
||||||
|
|||||||
Reference in New Issue
Block a user