From ac612987efd8daeadef894dab49846fc4e3455b6 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Fri, 1 Apr 2022 00:02:01 +0300 Subject: [PATCH] FIX: Build correct post and topic shareUrl (#16332) The links returned by post.url and topic.url are relative, but contain the subdirectory. When getAbsoluteURL is called to construct the complete share URL, it adds the host and the subdirectory again. As a result the created URLs contained the subdirectory twice. --- .../javascripts/discourse-common/addon/lib/get-url.js | 2 +- .../discourse/tests/unit/lib/get-url-test.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse-common/addon/lib/get-url.js b/app/assets/javascripts/discourse-common/addon/lib/get-url.js index 4a5a0f17150..fab9081c6fb 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/get-url.js +++ b/app/assets/javascripts/discourse-common/addon/lib/get-url.js @@ -41,7 +41,7 @@ export function getURLWithCDN(url) { } export function getAbsoluteURL(path) { - return baseUrl + path; + return baseUrl + withoutPrefix(path); } export function isAbsoluteURL(url) { diff --git a/app/assets/javascripts/discourse/tests/unit/lib/get-url-test.js b/app/assets/javascripts/discourse/tests/unit/lib/get-url-test.js index 4f2a337c468..25553f9fe17 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/get-url-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/get-url-test.js @@ -18,11 +18,20 @@ module("Unit | Utility | get-url", function () { }); test("getAbsoluteURL", function (assert) { - setupURL(null, "https://example.com", "/forum"); + setupURL(null, "https://example.com", null); assert.strictEqual( getAbsoluteURL("/cool/path"), "https://example.com/cool/path" ); + setupURL(null, "https://example.com/forum", "/forum"); + assert.strictEqual( + getAbsoluteURL("/cool/path"), + "https://example.com/forum/cool/path" + ); + assert.strictEqual( + getAbsoluteURL("/forum/cool/path"), + "https://example.com/forum/cool/path" + ); }); test("withoutPrefix", function (assert) {