Skip to content

Commit

Permalink
Fix some encoding issues
Browse files Browse the repository at this point in the history
* Now I recall some of it... Percent wasn't excluded in `cleanFilename` so we have to double check things. MongoDB doesn't care neither does AWS... but browsers do.

Post OpenUserJS#1847 and applies to OpenUserJS#200

NOTE:
* Test script RFC and n%
  • Loading branch information
Martii committed Nov 22, 2021
1 parent 4db4960 commit 4395356
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
20 changes: 18 additions & 2 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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') +
Expand Down
28 changes: 18 additions & 10 deletions views/includes/scripts/clipboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 4395356

Please sign in to comment.