🐛 fix double slashes in URLs (#506)

no issue

- update `config` service normalise blogUrl to non-trailing slash to match previous API behaviour
- fixes double slashes appearing in places around the app
- fixes "Redirect URI Mismatch" errors when using Ghost OAuth due to the double slashes
This commit is contained in:
Kevin Ansfield 2017-01-26 12:45:11 +00:00 committed by Katharina Irrgang
parent 66f7bad47b
commit ec760ca2f6
2 changed files with 42 additions and 0 deletions

View File

@ -17,6 +17,10 @@ export default Service.extend(_ProxyMixin, {
let configUrl = this.get('ghostPaths.url').api('configuration');
return this.get('ajax').request(configUrl).then((config) => {
// normalize blogUrl to non-trailing-slash
let [{blogUrl}] = config.configuration;
config.configuration[0].blogUrl = blogUrl.replace(/\/$/, '');
this.set('content', config.configuration[0]);
});
},

View File

@ -2,6 +2,7 @@ import {expect} from 'chai';
import {describe, it} from 'mocha';
import {setupTest} from 'ember-mocha';
import Pretender from 'pretender';
import wait from 'ember-test-helpers/wait';
function stubAvailableTimezonesEndpoint(server) {
server.get('/ghost/api/v0.1/configuration/timezones', function () {
@ -54,4 +55,41 @@ describe('Integration: Service: config', function () {
done();
});
});
it('normalizes blogUrl to non-trailing-slash', function (done) {
let stubBlogUrl = function stubBlogUrl(blogUrl) {
server.get('/ghost/api/v0.1/configuration/', function () {
return [
200,
{'Content-Type': 'application/json'},
JSON.stringify({
configuration: [{
blogUrl
}]
})
];
});
};
let service = this.subject();
stubBlogUrl('http://localhost:2368/');
service.fetch().then(() => {
expect(
service.get('blogUrl'), 'trailing-slash'
).to.equal('http://localhost:2368');
});
wait().then(() => {
stubBlogUrl('http://localhost:2368');
service.fetch().then(() => {
expect(
service.get('blogUrl'), 'non-trailing-slash'
).to.equal('http://localhost:2368');
done();
});
});
});
});