From aa92db985060451198239d297503bbaa0b318e09 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 16 Jul 2024 03:10:54 +0200 Subject: [PATCH] [UI] A more robust way to encode/decode URI arguments. --- .../backend/http/webapp/src/utils/Url.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/platypush/backend/http/webapp/src/utils/Url.vue b/platypush/backend/http/webapp/src/utils/Url.vue index 4a7e17d9e3..6bd00db4ac 100644 --- a/platypush/backend/http/webapp/src/utils/Url.vue +++ b/platypush/backend/http/webapp/src/utils/Url.vue @@ -16,7 +16,7 @@ export default { .reduce((acc, obj) => { const tokens = obj.split('=') if (tokens[0]?.length) - acc[tokens[0]] = tokens[1] + acc[tokens[0]] = decodeURIComponent(tokens[1]) return acc }, {}) }, @@ -40,10 +40,24 @@ export default { window.location.href = location }, + encodeValue(value) { + if (!value?.length || value === 'null' || value === 'undefined') + return '' + + // Don't re-encode the value if it's already encoded + if (value.match(/%[0-9A-F]{2}/i)) + return value + + return encodeURIComponent(value) + }, + fragmentFromArgs(args) { return Object.entries(args) + .filter( + ([key, value]) => this.encodeValue(key)?.length && this.encodeValue(value)?.length + ) .map( - ([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}` + ([key, value]) => `${this.encodeValue(key)}=${this.encodeValue(value)}` ) .join('&') },