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.
This commit is contained in:
Bianca Nenciu 2022-04-01 00:02:01 +03:00 committed by GitHub
parent ba509a93c2
commit ac612987ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -41,7 +41,7 @@ export function getURLWithCDN(url) {
} }
export function getAbsoluteURL(path) { export function getAbsoluteURL(path) {
return baseUrl + path; return baseUrl + withoutPrefix(path);
} }
export function isAbsoluteURL(url) { export function isAbsoluteURL(url) {

View File

@ -18,11 +18,20 @@ module("Unit | Utility | get-url", function () {
}); });
test("getAbsoluteURL", function (assert) { test("getAbsoluteURL", function (assert) {
setupURL(null, "https://example.com", "/forum"); setupURL(null, "https://example.com", null);
assert.strictEqual( assert.strictEqual(
getAbsoluteURL("/cool/path"), getAbsoluteURL("/cool/path"),
"https://example.com/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) { test("withoutPrefix", function (assert) {