mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
🐛 Fixed redirects with special characters (#15533)
closes: https://github.com/TryGhost/Ghost/issues/15267 - This was because the URLs were not being encoded and matched correctly - it is solved by encoding the URL before adding to the router.
This commit is contained in:
parent
e2124314ed
commit
3424222597
@ -94,6 +94,13 @@ class DynamicRedirectManager {
|
||||
*/
|
||||
addRedirect(from, to, options = {}) {
|
||||
try {
|
||||
// encode "from" only if it's not a regex
|
||||
try {
|
||||
new RegExp(from);
|
||||
} catch (e) {
|
||||
from = encodeURI(from);
|
||||
}
|
||||
|
||||
const fromRegex = this.buildRegex(from);
|
||||
const redirectId = from;
|
||||
|
||||
|
@ -363,6 +363,26 @@ describe('DynamicRedirectManager', function () {
|
||||
should.equal(location, 'https://ghost.org/docs');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Url with special character redirect', function () {
|
||||
it('redirects urls with special characters', function () {
|
||||
const from = '/joloonii-surgaltuud/а-анлал/';
|
||||
const to = '/joloonii-angilal/а-ангилал';
|
||||
|
||||
manager.addRedirect(from, to);
|
||||
|
||||
req.url = from;
|
||||
|
||||
manager.handleRequest(req, res, function next() {
|
||||
should.fail(true, false, 'next should NOT have been called');
|
||||
});
|
||||
|
||||
// NOTE: max-age is "0" because it's not a permanent redirect
|
||||
should.equal(headers['Cache-Control'], 'public, max-age=0');
|
||||
should.equal(status, 302);
|
||||
should.equal(location, '/joloonii-angilal/а-ангилал');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with subdirectory configuration', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user