prevent JSON.parse fault when search is undefined

This commit is contained in:
卜木 2017-06-28 16:37:25 +08:00 committed by 花裤衩
parent ffd668fb7d
commit 56a048865d
1 changed files with 5 additions and 1 deletions

View File

@ -110,7 +110,11 @@
export function param2Obj(url) {
const search = url.split('?')[1];
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
if (search !== undefined) {
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
}
return {};
}
export function html2Text(val) {