🐛 Fix: change decodeURI -> decodeURIComponent & encode also

This commit is contained in:
PiEgg 2022-10-19 17:40:04 +08:00
parent 3c01861122
commit 7677f1ea2a

View File

@ -2,7 +2,7 @@ export const isUrl = (url: string): boolean => (url.startsWith('http://') || url
export const isUrlEncode = (url: string): boolean => { export const isUrlEncode = (url: string): boolean => {
url = url || '' url = url || ''
try { try {
return url !== decodeURI(url) return url !== decodeURIComponent(url)
} catch (e) { } catch (e) {
// if some error caught, try to let it go // if some error caught, try to let it go
return true return true
@ -11,7 +11,7 @@ export const isUrlEncode = (url: string): boolean => {
export const handleUrlEncode = (url: string): string => { export const handleUrlEncode = (url: string): string => {
if (!isUrlEncode(url)) { if (!isUrlEncode(url)) {
url = encodeURI(url) url = encodeURIComponent(url)
} }
return url return url
} }