diff --git a/controllers/user.js b/controllers/user.js index 2f916e1e4..63f444d14 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -2431,6 +2431,8 @@ exports.editScript = function (aReq, aRes, aNext) { var copyrights = null; var copyrightPrimary = null; var createdDate = null; + var tryURL = null; + var tryInstallNameBase = null; //--- if (aErr || !aScript) { @@ -2494,11 +2496,25 @@ exports.editScript = function (aReq, aRes, aNext) { script.scriptPermalinkInstallPageUrlMin = 'https://' + aReq.get('host') + script.scriptInstallPageXUrl + ".min.user.js"; + tryInstallNameBase = scriptStorage.getInstallNameBase(aReq); + + try { + tryURL = new URL('../' + tryInstallNameBase, 'https://example.org/'); + + if ( + decodeURIComponent(tryURL.toString()) !== 'https://example.org/' + tryInstallNameBase + ) { + tryInstallNameBase = scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }); + } + } catch (aE) { + tryInstallNameBase = scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }); + } + script.scriptRawPageUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/' + - scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) + // WATCHPOINT + tryInstallNameBase + (isLib ? '.js' : '.user.js'); script.scriptRawPageXUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/' + - scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) + // WATCHPOINT + tryInstallNameBase + (isLib ? '.min.js' : '.min.user.js'); script.scriptPermalinkRawPageUrl = 'https://' + aReq.get('host') + diff --git a/views/includes/scripts/clipboard.html b/views/includes/scripts/clipboard.html index 47b9daa19..b61c02ec3 100644 --- a/views/includes/scripts/clipboard.html +++ b/views/includes/scripts/clipboard.html @@ -115,8 +115,10 @@ '^(?:\\uFEFF)?\/\/ ==' + parser + '==([\\s\\S]*?)^\/\/ ==\/'+ parser + '==', 'm' ); + var username = '{{authedUser.name}}'; var names = null; var name = null; + var tryURL = null; var updateURL = null; var downloadURL = []; var activeIdx = 0; // Default if new @@ -130,16 +132,22 @@ names = block['name'].reverse(); name = cleanFilename(names[0]); if (name) { - updateURL = origin + '/meta/' + '{{authedUser.name}}' + '/' + name + '.meta.js'; - - downloadURL.push(origin + '/install/' + '{{authedUser.name}}' + '/' + - name + '.user.js'); - downloadURL.push(origin + '/install/' + '{{authedUser.name}}' + '/' + - name + '.min.user.js'); - downloadURL.push(origin + '/src/scripts/' + '{{authedUser.name}}' + '/' + - name + '.user.js'); - downloadURL.push(origin + '/src/scripts/' + '{{authedUser.name}}' + '/' + - name + '.min.user.js'); + try { + tryURL = new URL('../' + name, origin); + + if (decodeURIComponent(tryURL.toString()) !== origin + '/' + name) { + name = encodeURIComponent(name); + } + } catch (aE) { + name = encodeURIComponent(name); + } + + updateURL = origin + '/meta/' + username + '/' + name + '.meta.js'; + + downloadURL.push(origin + '/install/' + username + '/' + name + '.user.js'); + downloadURL.push(origin + '/install/' + username + '/' + name + '.min.user.js'); + downloadURL.push(origin + '/src/scripts/' + username + '/' + name + '.user.js'); + downloadURL.push(origin + '/src/scripts/' + username + '/' + name + '.min.user.js'); // Find current active $('#install-targets li').each(function (aIdx) {