From fe0d912b97985a6272e720729aa6197e8e40274f Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Jan 2020 17:51:46 +0000 Subject: [PATCH] FIX: getURL on a subfolder site should ignore prefix in middle of URL (#8794) --- app/assets/javascripts/discourse.js.es6 | 2 +- test/javascripts/lib/discourse-test.js.es6 | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse.js.es6 b/app/assets/javascripts/discourse.js.es6 index 7b21f2bec66..8143ba27fca 100644 --- a/app/assets/javascripts/discourse.js.es6 +++ b/app/assets/javascripts/discourse.js.es6 @@ -29,8 +29,8 @@ const Discourse = Ember.Application.extend(FocusEvent, { // if it's a non relative URL, return it. if (url !== "/" && !/^\/[^\/]/.test(url)) return url; - if (url.indexOf(Discourse.BaseUri) !== -1) return url; if (url[0] !== "/") url = "/" + url; + if (url.startsWith(Discourse.BaseUri)) return url; return Discourse.BaseUri + url; }, diff --git a/test/javascripts/lib/discourse-test.js.es6 b/test/javascripts/lib/discourse-test.js.es6 index d2cf1112773..3d04bdb3507 100644 --- a/test/javascripts/lib/discourse-test.js.es6 +++ b/test/javascripts/lib/discourse-test.js.es6 @@ -10,6 +10,18 @@ QUnit.test("getURL on subfolder install", assert => { "/forum/u/neil", "relative url has subfolder" ); + + assert.equal( + Discourse.getURL("/svg-sprite/forum.example.com/svg-sprite.js"), + "/forum/svg-sprite/forum.example.com/svg-sprite.js", + "works when the url has the prefix in the middle" + ); + + assert.equal( + Discourse.getURL("/forum/t/123"), + "/forum/t/123", + "does not prefix if the URL is already prefixed" + ); }); QUnit.test("getURLWithCDN on subfolder install with S3", assert => {