element getPropByPath是不是存在漏洞?

3wabscal  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(97)

`
export function getPropByPath(obj, path, strict) {
let tempObj = obj;
path = path.replace(/[(\w+)]/g, '.$1');
path = path.replace(/^./, '');

let keyArr = path.split('.');
let i = 0;
for (let len = keyArr.length; i < len - 1; ++i) {
if (!tempObj && !strict) break;
let key = keyArr[i];
if (key in tempObj) {
tempObj = tempObj[key];
} else {
if (strict) {
throw new Error('please transfer a valid prop path to form item!');
}
break;
}
}
return {
o: tempObj,
k: keyArr[i],
v: tempObj ? tempObj[keyArr[i]] : null
};
};
`
key in tempObj 这里是不是要先判断下tempObj是不是对象。如果不是抛出和下面一样的异常?

dffbzjpn

dffbzjpn1#

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

相关问题