mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #9492, keep query params on redirect
This commit is contained in:
@@ -194,9 +194,8 @@ module.exports = function (middleware) {
|
|||||||
if (!userslug) {
|
if (!userslug) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const path = req.path.replace(/^\/api/, '')
|
const path = req.url.replace(/^\/api/, '')
|
||||||
.replace('uid', 'user')
|
.replace(`/uid/${uid}`, () => `/user/${userslug}`);
|
||||||
.replace(uid, () => userslug);
|
|
||||||
controllers.helpers.redirect(res, path);
|
controllers.helpers.redirect(res, path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1050,6 +1050,16 @@ describe('Controllers', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should redirect to userslug and keep query params', (done) => {
|
||||||
|
request(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`, { json: true }, (err, res, body) => {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
assert.equal(res.headers['x-redirect'], '/user/foo/topics?foo=bar');
|
||||||
|
assert.equal(body, '/user/foo/topics?foo=bar');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should 404 if user does not exist', (done) => {
|
it('should 404 if user does not exist', (done) => {
|
||||||
request(`${nconf.get('url')}/api/uid/123123`, { json: true }, (err, res) => {
|
request(`${nconf.get('url')}/api/uid/123123`, { json: true }, (err, res) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user