Skip to content

Fix some bugs with encoding #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ exports.adminUserUpdate = function (aReq, aRes, aNext) {

// Make sure the change is reflected in the session store
updateSessions(aReq, aUser, function (aErr, aSess) {
aRes.redirect(user.userPageUrl);
aRes.redirect(user.userPageUri);
});
});
});
Expand Down Expand Up @@ -497,6 +497,6 @@ exports.authAsUser = function (aReq, aRes, aNext) {

aReq.session.user = user;

aRes.redirect(encodeURI(user.userPageUrl)); // NOTE: Watchpoint
aRes.redirect(user.userPageUri);
});
};
10 changes: 5 additions & 5 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ exports.callback = function (aReq, aRes, aNext) {
var username = aReq.session.username;
var newstrategy = aReq.session.newstrategy;
var strategyInstance = null;
var doneUrl = aReq.session.user ? '/user/preferences' : '/';
var doneUri = aReq.session.user ? '/user/preferences' : '/';

// The callback was called improperly
if (!strategy || !username) {
Expand Down Expand Up @@ -231,7 +231,7 @@ exports.callback = function (aReq, aRes, aNext) {
console.error(chalk.red('`User` not found'));
}

aRes.redirect(doneUrl + (doneUrl === '/' ? 'register' : '') + '?authfail');
aRes.redirect(doneUri + (doneUri === '/' ? 'register' : '') + '?authfail');
return;
}

Expand Down Expand Up @@ -263,16 +263,16 @@ exports.callback = function (aReq, aRes, aNext) {
addSession(aReq, aUser, function () {
if (newstrategy && newstrategy !== strategy) {
// Allow a user to link to another account
aRes.redirect('/auth/' + newstrategy);
aRes.redirect('/auth/' + newstrategy); // NOTE: Watchpoint... careful with encoding
return;
} else {
// Delete the username that was temporarily stored
delete aReq.session.username;
delete aReq.session.newstrategy;
doneUrl = aReq.session.redirectTo;
doneUri = aReq.session.redirectTo;
delete aReq.session.redirectTo;

aRes.redirect(doneUrl);
aRes.redirect(doneUri);
return;
}
});
Expand Down
12 changes: 8 additions & 4 deletions controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,10 @@ exports.createTopic = function (aReq, aRes, aNext) {
return;
}

aRes.redirect(encodeURI(aDiscussion.path
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
aRes.redirect(aDiscussion.path.split('/').map(function (aStr) {
return encodeURIComponent(aStr);
}).join('/')
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : ''));
});
};

Expand Down Expand Up @@ -560,8 +562,10 @@ exports.createComment = function (aReq, aRes, aNext) {
}

postComment(authedUser, aDiscussion, content, false, function (aErr, aDiscussion) {
aRes.redirect(encodeURI(aDiscussion.path
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
aRes.redirect(aDiscussion.path.split('/').map(function (aStr) {
return encodeURIComponent(aStr);
}).join('/') +
(aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : ''));
});
});
};
6 changes: 3 additions & 3 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ exports.register = function (aReq, aRes) {

exports.logout = function (aReq, aRes) {
var authedUser = aReq.session.user;
var redirectUrl = getRedirect(aReq);
var redirectUri = getRedirect(aReq); // NOTE: Watchpoint

if (!authedUser) {
aRes.redirect(redirectUrl);
aRes.redirect(redirectUri);
return;
}

User.findOne({ _id: authedUser._id }, function (aErr, aUser) {
removeSession(aReq, aUser, function () {
aRes.redirect(redirectUrl);
aRes.redirect(redirectUri);
});
});
};
20 changes: 13 additions & 7 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ exports.open = function (aReq, aRes, aNext) {
discussionLib.postTopic(authedUser, category.slug, topic, content, true,
function (aDiscussion) {
if (!aDiscussion) {
aRes.redirect('/' + encodeURI(category) + '/open');
aRes.redirect('/' + category.slugUri + '/open');
return;
}

aRes.redirect(encodeURI(aDiscussion.path +
(aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
aRes.redirect(aDiscussion.path.split('/').map(function (aStr) {
return encodeURIComponent(aStr);
}).join('/') +
(aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : ''));
}
);
} else {
Expand Down Expand Up @@ -439,8 +441,10 @@ exports.comment = function (aReq, aRes, aNext) {

discussionLib.postComment(authedUser, aIssue, content, false,
function (aErr, aDiscussion) {
aRes.redirect(encodeURI(aDiscussion.path
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
aRes.redirect(aDiscussion.path.split('/').map(function (aStr) {
return encodeURIComponent(aStr);
}).join('/') +
(aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : ''));
});
});
});
Expand Down Expand Up @@ -487,8 +491,10 @@ exports.changeStatus = function (aReq, aRes, aNext) {

if (changed) {
aIssue.save(function (aErr, aDiscussion) {
aRes.redirect(encodeURI(aDiscussion.path
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
aRes.redirect(aDiscussion.path.split('/').map(function (aStr) {
return encodeURIComponent(aStr);
}).join('/') +
(aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : ''));
});
} else {
aNext();
Expand Down
26 changes: 13 additions & 13 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,15 @@ exports.edit = function (aReq, aRes, aNext) {
if (aReq.body.remove) {
// POST
scriptStorage.deleteScript(aScript.installName, function () {
aRes.redirect(authedUser.userScriptListPageUrl);
aRes.redirect(authedUser.userScriptListPageUri);
});
} else if (typeof aReq.body.about !== 'undefined') {
// POST
aScript.about = aReq.body.about;
scriptGroups = (aReq.body.groups || '');
scriptGroups = scriptGroups.split(/,/);
addScriptToGroups(aScript, scriptGroups, function () {
aRes.redirect(script.scriptPageUrl);
aRes.redirect(script.scriptPageUri);
});
} else {
// GET
Expand All @@ -495,20 +495,20 @@ exports.edit = function (aReq, aRes, aNext) {
// Script voting
exports.vote = function (aReq, aRes, aNext) {
//
var url = aReq._parsedUrl.pathname.split('/');
var uri = aReq._parsedUrl.pathname.split('/');
var vote = aReq.params.vote;
var unvote = false;

var isLib = aReq.params.isLib;
var installNameBase = scriptStorage.getInstallNameBase(aReq);

// ---
if (url.length > 5) {
url.pop();
if (uri.length > 5) {
uri.pop();
}
url.shift();
url.shift();
url = '/' + url.join('/');
uri.shift();
uri.shift();
uri = '/' + uri.join('/');

if (vote === 'up') {
vote = true;
Expand All @@ -517,7 +517,7 @@ exports.vote = function (aReq, aRes, aNext) {
} else if (vote === 'unvote') {
unvote = true;
} else {
aRes.redirect(url);
aRes.redirect(uri);
return;
}

Expand All @@ -530,7 +530,7 @@ exports.vote = function (aReq, aRes, aNext) {

// ---
if (aErr || !aScript) {
aRes.redirect(url);
aRes.redirect(uri);
return;
}

Expand All @@ -543,15 +543,15 @@ exports.vote = function (aReq, aRes, aNext) {
function saveScript() {
if (!flags) {
aScript.save(function (aErr, aScript) {
aRes.redirect(url);
aRes.redirect(uri);
});
return;
}

flagLib.getAuthor(aScript, function (aAuthor) {
flagLib.saveContent(Script, aScript, aAuthor, flags,
function (aFlagged) {
aRes.redirect(url);
aRes.redirect(uri);
});
});
}
Expand All @@ -565,7 +565,7 @@ exports.vote = function (aReq, aRes, aNext) {
}

if (authedUser._id == aScript._authorId || (!aVoteModel && unvote)) {
aRes.redirect(url);
aRes.redirect(uri);
return;
} else if (!aVoteModel) {
aVoteModel = new Vote({
Expand Down
10 changes: 9 additions & 1 deletion controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var RepoManager = require('../libs/repoManager');

var cleanFilename = require('../libs/helpers').cleanFilename;
var findDeadorAlive = require('../libs/remove').findDeadorAlive;
var encode = require('../libs/helpers').encode;

//--- Configuration inclusions
var userRoles = require('../models/userRoles.json');
Expand Down Expand Up @@ -88,6 +89,9 @@ function getInstallNameBase(aReq, aOptions) {
base = encodeURIComponent(username) + '/' + encodeURIComponent(scriptname);
break;

case 'url':
base = encode(username) + '/' + encode(scriptname);

default:
base = username + '/' + scriptname;
}
Expand Down Expand Up @@ -733,7 +737,11 @@ exports.webhook = function (aReq, aRes) {
payload.commits.forEach(function (aCommit) {
aCommit.modified.forEach(function (aFilename) {
if (aFilename.substr(-8) === '.user.js') {
repo[aFilename] = '/' + encodeURI(aFilename);
console.log([
'Webhook filename:',
' ' + aFilename
].join('\n')); // TODO: After some data collected, reaffirm and remove this
repo[aFilename] = '/' + encodeURI(aFilename); // NOTE: Watchpoint
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some data here:

aFilename := src/RFC 2606§3/RFC 2606§3 - ä %, Unit Test/RFC 2606§3 - ä %, Unit Test.user.js on trigger.

Refs:

  1. 0d06785/libs/repoManager.js#L119-L120
  2. https://raw.githubusercontent.com/Martii/UserScripts/master/src/RFC%202606%C2%A73/RFC%202606%C2%A73%20-%20%C3%A4%20%25%2C%20Unit%20Test/RFC%202606%C2%A73%20-%20%C3%A4%20%25%2C%20Unit%20Test.user.js (Raw URL copied from address bar)
  3. encodeURI('RFC 2606§3 - ä %, Unit Test.user.js') := RFC%202606%C2%A73%20-%20%C3%A4%20%25,%20Unit%20Test.user.js
  4. encodeURIComponent('RFC 2606§3 - ä %, Unit Test.user.js') := RFC%202606%C2%A73%20-%20%C3%A4%20%25%2C%20Unit%20Test.user.js
  5. /Martii/UserScripts/raw/master/src/RFC%202606%C2%A73/RFC%202606%C2%A73%20-%20%C3%A4%20%25%2C%20Unit%20Test/RFC%202606%C2%A73%20-%20%C3%A4%20%25%2C%20Unit%20Test.user.js (the href attribute from here on the Raw button)

@Zren Cc: @sizzlemctwizzle
Would either of you say there is an issue here? (EDITED: look for the comma... e.g. %2C and , respectively ... in list item 2, 3, 4 and 5 )

Everything appears alright on pro with the JSON... but I've also picked simple values in the Userscript and something still doesn't feel right.

}
});
});
Expand Down
Loading