Skip to content

Commit 44395c2

Browse files
authored
FIX: do not prepend #fragment with https:// on link modal (#36619)
`prefixProtocol` is used by the upsert hyperlink modal, it was prepending `https://` to URLs starting with `#fragment`, which can be used for topic anchoring. This PR changes `prefixProtocol` so it doesn't prepend `https://` for strings started with a `#`.
1 parent 278e36c commit 44395c2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

frontend/discourse/app/lib/url.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,12 @@ export function prefixProtocol(url) {
503503
return `https:${url}`;
504504
}
505505

506-
if (url.startsWith("/") || url.includes("://") || url.startsWith("mailto:")) {
506+
if (
507+
url.startsWith("/") ||
508+
url.includes("://") ||
509+
url.startsWith("mailto:") ||
510+
url.startsWith("#")
511+
) {
507512
return url;
508513
}
509514

frontend/discourse/tests/unit/lib/url-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ module("Unit | Utility | url", function (hooks) {
218218
"ftp://www.discourse.org"
219219
);
220220
assert.strictEqual(prefixProtocol("/my/preferences"), "/my/preferences");
221+
assert.strictEqual(prefixProtocol("#anchor-fragment"), "#anchor-fragment");
221222
});
222223

223224
test("getCategoryAndTagUrl", function (assert) {

0 commit comments

Comments
 (0)