Merge pull request #5794 from NodeBB/fix-5793

Fix #5793
v1.18.x
Barış Soner Uşaklı 8 years ago committed by GitHub
commit c91632e041

@ -293,11 +293,21 @@ $(document).ready(function () {
headers: { headers: {
'X-Return-To': app.previousUrl, 'X-Return-To': app.previousUrl,
}, },
success: function (data) { success: function (data, textStatus, xhr) {
if (!data) { if (!data) {
return; return;
} }
if (xhr.getResponseHeader('X-Redirect')) {
return callback({
data: {
status: 302,
responseJSON: data,
},
textStatus: 'error',
});
}
ajaxify.data = data; ajaxify.data = data;
data.config = config; data.config = config;

@ -16,7 +16,7 @@ define('scrollStop', function () {
$(element).on('mousewheel', function (e) { $(element).on('mousewheel', function (e) {
var scrollTop = this.scrollTop; var scrollTop = this.scrollTop;
var scrollHeight = this.scrollHeight; var scrollHeight = this.scrollHeight;
var elementHeight = this.getBoundingClientRect().height; var elementHeight = Math.round(this.getBoundingClientRect().height);
if ( if (
(e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up (e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up

@ -45,7 +45,7 @@ exports.handleErrors = function (err, req, res, next) { // eslint-disable-line n
var status = parseInt(err.status, 10); var status = parseInt(err.status, 10);
if ((status === 302 || status === 308) && err.path) { if ((status === 302 || status === 308) && err.path) {
return res.locals.isAPI ? res.status(status).json(err.path) : res.redirect(err.path); return res.locals.isAPI ? res.set('X-Redirect', err.path).status(200).json(err.path) : res.redirect(err.path);
} }
winston.error(req.path + '\n', err.stack); winston.error(req.path + '\n', err.stack);

@ -53,7 +53,7 @@ helpers.notAllowed = function (req, res, error) {
helpers.redirect = function (res, url) { helpers.redirect = function (res, url) {
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.status(308).json(url); res.set('X-Redirect', url).status(200).json(url);
} else { } else {
res.redirect(nconf.get('relative_path') + encodeURI(url)); res.redirect(nconf.get('relative_path') + encodeURI(url));
} }

@ -808,7 +808,8 @@ describe('Controllers', function () {
it('should redirect to account page with logged in user', function (done) { it('should redirect to account page with logged in user', function (done) {
request(nconf.get('url') + '/api/login', { jar: jar, json: true }, function (err, res, body) { request(nconf.get('url') + '/api/login', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-redirect'], '/user/foo');
assert.equal(body, '/user/foo'); assert.equal(body, '/user/foo');
done(); done();
}); });
@ -825,7 +826,8 @@ describe('Controllers', function () {
it('should redirect to userslug', function (done) { it('should redirect to userslug', function (done) {
request(nconf.get('url') + '/api/uid/' + fooUid, { json: true }, function (err, res, body) { request(nconf.get('url') + '/api/uid/' + fooUid, { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-redirect'], '/user/foo');
assert.equal(body, '/user/foo'); assert.equal(body, '/user/foo');
done(); done();
}); });
@ -1238,10 +1240,11 @@ describe('Controllers', function () {
}); });
it('should return correct post path', function (done) { it('should return correct post path', function (done) {
request(nconf.get('url') + '/api/post/' + pid, function (err, res, body) { request(nconf.get('url') + '/api/post/' + pid, { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(body, '"/topic/1/test-topic-title/1"'); assert.equal(res.headers['x-redirect'], '/topic/1/test-topic-title/1');
assert.equal(body, '/topic/1/test-topic-title/1');
done(); done();
}); });
}); });
@ -1411,7 +1414,8 @@ describe('Controllers', function () {
request(nconf.get('url') + '/api/users', { json: true }, function (err, res, body) { request(nconf.get('url') + '/api/users', { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-redirect'], '/api/popular');
assert(body, '/api/popular'); assert(body, '/api/popular');
done(); done();
}); });
@ -1521,7 +1525,8 @@ describe('Controllers', function () {
it('should redirect if topic index is negative', function (done) { it('should redirect if topic index is negative', function (done) {
request(nconf.get('url') + '/api/category/' + category.slug + '/-10', function (err, res) { request(nconf.get('url') + '/api/category/' + category.slug + '/-10', function (err, res) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.ok(res.headers['x-redirect']);
done(); done();
}); });
}); });
@ -1627,7 +1632,8 @@ describe('Controllers', function () {
function (category, next) { function (category, next) {
request(nconf.get('url') + '/api/category/' + category.slug, { jar: jar, json: true }, function (err, res, body) { request(nconf.get('url') + '/api/category/' + category.slug, { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-redirect'], 'https://nodebb.org');
assert.equal(body, 'https://nodebb.org'); assert.equal(body, 'https://nodebb.org');
next(); next();
}); });
@ -1754,10 +1760,11 @@ describe('Controllers', function () {
}); });
it('should redirect if page is out of bounds', function (done) { it('should redirect if page is out of bounds', function (done) {
request(nconf.get('url') + '/api/unread?page=-1', { jar: jar }, function (err, res, body) { request(nconf.get('url') + '/api/unread?page=-1', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(res.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(body, '"/unread?page=1"'); assert.equal(res.headers['x-redirect'], '/unread?page=1');
assert.equal(body, '/unread?page=1');
done(); done();
}); });
}); });

@ -591,10 +591,11 @@ describe('Messaging Library', function () {
}); });
it('should redirect to chats page', function (done) { it('should redirect to chats page', function (done) {
request(nconf.get('url') + '/api/chats', { jar: jar }, function (err, response, body) { request(nconf.get('url') + '/api/chats', { jar: jar, json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(body, '"/user/herp/chats"'); assert.equal(res.statusCode, 200);
assert.equal(response.statusCode, 308); assert.equal(res.headers['x-redirect'], '/user/herp/chats');
assert.equal(body, '/user/herp/chats');
done(); done();
}); });
}); });

@ -791,10 +791,11 @@ describe('Topic\'s', function () {
}); });
it('should redirect if post index is out of range', function (done) { it('should redirect if post index is out of range', function (done) {
request(nconf.get('url') + '/api/topic/' + topicData.slug + '/-1', function (err, response, body) { request(nconf.get('url') + '/api/topic/' + topicData.slug + '/-1', { json: true }, function (err, res, body) {
assert.ifError(err); assert.ifError(err);
assert.equal(response.statusCode, 308); assert.equal(res.statusCode, 200);
assert.equal(body, '"/topic/13/topic-for-controller-test"'); assert.equal(res.headers['x-redirect'], '/topic/13/topic-for-controller-test');
assert.equal(body, '/topic/13/topic-for-controller-test');
done(); done();
}); });
}); });

Loading…
Cancel
Save