From ec760ca2f643f42842a41625bf6e5df3741cb48a Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 26 Jan 2017 12:45:11 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20double=20slashes=20in=20UR?= =?UTF-8?q?Ls=20(#506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ghost/admin/app/services/config.js | 4 ++ .../tests/integration/services/config-test.js | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/ghost/admin/app/services/config.js b/ghost/admin/app/services/config.js index ece2b012f7..219af15052 100644 --- a/ghost/admin/app/services/config.js +++ b/ghost/admin/app/services/config.js @@ -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]); }); }, diff --git a/ghost/admin/tests/integration/services/config-test.js b/ghost/admin/tests/integration/services/config-test.js index 3da906ac2e..e11011a300 100644 --- a/ghost/admin/tests/integration/services/config-test.js +++ b/ghost/admin/tests/integration/services/config-test.js @@ -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(); + }); + }); + }); });