From a3cdb4cca1f50e1fbd30b379e8b434f2b6338526 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 27 Mar 2022 02:21:56 +0900 Subject: [PATCH] fix: Handle decodeURIComponent error (#8411) --- packages/client/src/components/global/url.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/client/src/components/global/url.vue b/packages/client/src/components/global/url.vue index 56a8c3453a..09513670d3 100644 --- a/packages/client/src/components/global/url.vue +++ b/packages/client/src/components/global/url.vue @@ -49,14 +49,22 @@ export default defineComponent({ }, {}, 'closed'); }); + function safeURIDecode(str: string) { + try { + return decodeURIComponent(str); + } catch { + return str; + } + } + return { local, schema: url.protocol, hostname: decodePunycode(url.hostname), port: url.port, - pathname: decodeURIComponent(url.pathname), - query: decodeURIComponent(url.search), - hash: decodeURIComponent(url.hash), + pathname: safeURIDecode(url.pathname), + query: safeURIDecode(url.search), + hash: safeURIDecode(url.hash), self: self, attr: self ? 'to' : 'href', target: self ? null : '_blank',