From 65dfec9acf4a9f821cbf4b03b2936b760146c488 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sat, 20 Jul 2019 01:18:11 -0700 Subject: [PATCH 1/2] Minor refactor on WebUI download page --- src/webui/www/private/download.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/webui/www/private/download.html b/src/webui/www/private/download.html index 1699dbf50..918a264db 100644 --- a/src/webui/www/private/download.html +++ b/src/webui/www/private/download.html @@ -142,9 +142,8 @@ const encodedUrls = new URI().getData('urls'); if (encodedUrls) { - const urls = []; - encodedUrls.split('|').each(function(url) { - urls.push(decodeURIComponent(url)); + const urls = encodedUrls.split('|').map(function(url) { + return decodeURIComponent(url); }); if (urls.length) From c17d653544896eb88c6fea47ec333a9601aaef70 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sat, 20 Jul 2019 01:21:49 -0700 Subject: [PATCH 2/2] Fix WebUI removing parameters from magnet links Closes #10939 --- src/webui/www/private/scripts/client.js | 15 +++++---------- src/webui/www/private/scripts/mocha-init.js | 7 +++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index f1dba3980..c093c9a0a 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -967,18 +967,13 @@ function registerMagnetHandler() { function handleDownloadParam() { // Extract torrent URL from download param in WebUI URL hash - const hashParams = getHashParamsFromUrl(); - const url = hashParams.download; - if (!url) + const downloadHash = "#download="; + if (location.hash.indexOf(downloadHash) !== 0) return; - // Remove the download param from WebUI URL hash - delete hashParams.download; - let newHash = Object.toQueryString(hashParams); - newHash = newHash ? ('#' + newHash) : ''; - history.replaceState('', document.title, - (location.pathname + location.search + newHash)); - + const url = location.hash.substring(downloadHash.length); + // Remove the processed hash from the URL + history.replaceState('', document.title, (location.pathname + location.search)); showDownloadPage([url]); } diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index f4b48daa9..da447f0d8 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -135,8 +135,11 @@ const initializeWindows = function() { showDownloadPage = function(urls) { const id = 'downloadPage'; let contentUrl = 'download.html'; - if (urls && urls.length) - contentUrl += '?urls=' + urls.join("|"); + if (urls && (urls.length > 0)) { + contentUrl += ('?urls=' + urls.map(function(url) { + return encodeURIComponent(url); + }).join("|")); + } new MochaUI.Window({ id: id,