From 5beb1b2cd06e5655ad921052b05c9201ba42a7a2 Mon Sep 17 00:00:00 2001 From: brvphoenix Date: Fri, 19 Mar 2021 01:27:36 -0700 Subject: [PATCH] WebUI: Avoid decoding strings repeatedly Fix #14553 --- src/webui/www/private/confirmfeeddeletion.html | 2 +- src/webui/www/private/confirmruleclear.html | 2 +- src/webui/www/private/confirmruledeletion.html | 2 +- src/webui/www/private/edittracker.html | 5 ++--- src/webui/www/private/rename.html | 2 +- src/webui/www/private/rename_file.html | 3 +-- src/webui/www/private/scripts/mocha-init.js | 4 ++-- src/webui/www/private/setlocation.html | 2 +- src/webui/www/private/views/rss.html | 3 ++- src/webui/www/private/views/rssDownloader.html | 6 ++++-- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/webui/www/private/confirmfeeddeletion.html b/src/webui/www/private/confirmfeeddeletion.html index ecbc6bd29..77b0cbb4b 100644 --- a/src/webui/www/private/confirmfeeddeletion.html +++ b/src/webui/www/private/confirmfeeddeletion.html @@ -26,7 +26,7 @@ noCache: true, method: 'post', data: { - path: path + path: decodeURIComponent(path) }, onComplete: (response) => { ++completionCount; diff --git a/src/webui/www/private/confirmruleclear.html b/src/webui/www/private/confirmruleclear.html index e9640a32d..9c056228d 100644 --- a/src/webui/www/private/confirmruleclear.html +++ b/src/webui/www/private/confirmruleclear.html @@ -22,7 +22,7 @@ new Event(e).stop(); let completionCount = 0; rules.forEach((rule) => { - window.parent.qBittorrent.RssDownloader.modifyRuleState(rule, 'previouslyMatchedEpisodes', [], () => { + window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), 'previouslyMatchedEpisodes', [], () => { ++completionCount; if (completionCount === rules.length) { window.parent.qBittorrent.RssDownloader.updateRulesList(); diff --git a/src/webui/www/private/confirmruledeletion.html b/src/webui/www/private/confirmruledeletion.html index 687636936..44433ff11 100644 --- a/src/webui/www/private/confirmruledeletion.html +++ b/src/webui/www/private/confirmruledeletion.html @@ -27,7 +27,7 @@ noCache: true, method: 'post', data: { - ruleName: rule + ruleName: decodeURIComponent(rule) }, onComplete: (response) => { ++completionCount; diff --git a/src/webui/www/private/edittracker.html b/src/webui/www/private/edittracker.html index 4838680e5..c4ffc1ac9 100644 --- a/src/webui/www/private/edittracker.html +++ b/src/webui/www/private/edittracker.html @@ -33,8 +33,7 @@ if (!currentUrl) return false; - const decodedUrl = decodeURIComponent(currentUrl); - $('trackerUrl').value = decodedUrl; + $('trackerUrl').value = currentUrl; $('trackerUrl').focus(); $('editTrackerButton').addEvent('click', function(e) { @@ -45,7 +44,7 @@ method: 'post', data: { hash: hash, - origUrl: decodedUrl, + origUrl: currentUrl, newUrl: $('trackerUrl').value }, onComplete: function() { diff --git a/src/webui/www/private/rename.html b/src/webui/www/private/rename.html index daed2844f..6269a1422 100644 --- a/src/webui/www/private/rename.html +++ b/src/webui/www/private/rename.html @@ -33,7 +33,7 @@ const name = new URI().getData('name'); // set text field to current value if (name) - $('rename').value = decodeURIComponent(name); + $('rename').value = name; $('rename').focus(); $('renameButton').addEvent('click', function(e) { diff --git a/src/webui/www/private/rename_file.html b/src/webui/www/private/rename_file.html index fb48780a3..35711bf90 100644 --- a/src/webui/www/private/rename_file.html +++ b/src/webui/www/private/rename_file.html @@ -32,10 +32,9 @@ window.addEvent('domready', function() { const hash = new URI().getData('hash'); - const path = new URI().getData('path'); + const oldPath = new URI().getData('path'); const isFolder = ((new URI().getData('isFolder')) === 'true'); - const oldPath = decodeURIComponent(path); const oldName = window.qBittorrent.Filesystem.fileName(oldPath); $('rename').value = oldName; $('rename').focus(); diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 51b345b55..e6b093f72 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -120,9 +120,9 @@ const initializeWindows = function() { const id = 'downloadPage'; let contentUrl = 'download.html'; if (urls && (urls.length > 0)) { - contentUrl += ('?urls=' + urls.map(function(url) { + contentUrl += ('?urls=' + encodeURIComponent(urls.map(function(url) { return encodeURIComponent(url); - }).join("|")); + }).join("|"))); } new MochaUI.Window({ diff --git a/src/webui/www/private/setlocation.html b/src/webui/www/private/setlocation.html index e3de3ff29..2e7622f2d 100644 --- a/src/webui/www/private/setlocation.html +++ b/src/webui/www/private/setlocation.html @@ -33,7 +33,7 @@ const path = new URI().getData('path'); // set text field to current value if (path) - $('setLocation').value = window.qBittorrent.Misc.escapeHtml(decodeURIComponent(path)); + $('setLocation').value = window.qBittorrent.Misc.escapeHtml(path); $('setLocation').focus(); $('setLocationButton').addEvent('click', function(e) { diff --git a/src/webui/www/private/views/rss.html b/src/webui/www/private/views/rss.html index b81061266..12664cd1b 100644 --- a/src/webui/www/private/views/rss.html +++ b/src/webui/www/private/views/rss.html @@ -697,11 +697,12 @@ }; const removeItem = (paths) => { + const encodedPaths = paths.map((path) => encodeURIComponent(path)); new MochaUI.Window({ id: 'confirmFeedDeletionPage', title: 'QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=RSSWidget]', loadMethod: 'iframe', - contentURL: 'confirmfeeddeletion.html?paths=' + encodeURIComponent(paths.join('|')), + contentURL: 'confirmfeeddeletion.html?paths=' + encodeURIComponent(encodedPaths.join('|')), scrollbars: false, resizable: false, maximizable: false, diff --git a/src/webui/www/private/views/rssDownloader.html b/src/webui/www/private/views/rssDownloader.html index e4989d193..884652347 100644 --- a/src/webui/www/private/views/rssDownloader.html +++ b/src/webui/www/private/views/rssDownloader.html @@ -535,11 +535,12 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also }; const removeRules = (rules) => { + const encodedRules = rules.map((rule) => encodeURIComponent(rule)); new MochaUI.Window({ id: 'removeRulePage', title: 'QBT_TR(Rule deletion confirmation)QBT_TR[CONTEXT=AutomatedRssDownloader]', loadMethod: 'iframe', - contentURL: 'confirmruledeletion.html?rules=' + encodeURIComponent(rules.join('|')), + contentURL: 'confirmruledeletion.html?rules=' + encodeURIComponent(encodedRules.join('|')), scrollbars: false, resizable: false, maximizable: false, @@ -549,11 +550,12 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also }; const clearDownloadedEpisodes = (rules) => { + const encodedRules = rules.map((rule) => encodeURIComponent(rule)); new MochaUI.Window({ id: 'clearRulesPage', title: 'QBT_TR(New rule name)QBT_TR[CONTEXT=AutomatedRssDownloader]', loadMethod: 'iframe', - contentURL: 'confirmruleclear.html?rules=' + encodeURIComponent(rules.join('|')), + contentURL: 'confirmruleclear.html?rules=' + encodeURIComponent(encodedRules.join('|')), scrollbars: false, resizable: false, maximizable: false,