Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 fix double slashes in URLs (#506)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kevinansfield authored and kirrg001 committed Jan 26, 2017
1 parent 7af0f51 commit 3b96baf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
},
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/services/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});
});
});
});

0 comments on commit 3b96baf

Please sign in to comment.