mirror of
https://github.com/discourse/discourse.git
synced 2025-03-03 06:28:41 +08:00
FIX: relative links in the insert hyperlink modal (#30842)
When trying to insert schemaless or relative links using the "insert hyperlink modal" in the composer, the resulting link would be wrongly prefixed with "https://"
This commit is contained in:
parent
560c1875a5
commit
359bbbe617
@ -483,9 +483,21 @@ export function setURLContainer(container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function prefixProtocol(url) {
|
export function prefixProtocol(url) {
|
||||||
return !url.includes("://") && !url.startsWith("mailto:")
|
if (!url || typeof url !== "string") {
|
||||||
? "https://" + url
|
return url;
|
||||||
: url;
|
}
|
||||||
|
|
||||||
|
url = url.trim();
|
||||||
|
|
||||||
|
if (url.startsWith("//")) {
|
||||||
|
return `https:${url}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.startsWith("/") || url.includes("://") || url.startsWith("mailto:")) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `https://${url}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCategoryAndTagUrl(category, subcategories, tag) {
|
export function getCategoryAndTagUrl(category, subcategories, tag) {
|
||||||
|
@ -184,6 +184,15 @@ module("Unit | Utility | url", function (hooks) {
|
|||||||
prefixProtocol("www.discourse.org/mailto:foo"),
|
prefixProtocol("www.discourse.org/mailto:foo"),
|
||||||
"https://www.discourse.org/mailto:foo"
|
"https://www.discourse.org/mailto:foo"
|
||||||
);
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
prefixProtocol("http://www.discourse.org"),
|
||||||
|
"http://www.discourse.org"
|
||||||
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
prefixProtocol("ftp://www.discourse.org"),
|
||||||
|
"ftp://www.discourse.org"
|
||||||
|
);
|
||||||
|
assert.strictEqual(prefixProtocol("/my/preferences"), "/my/preferences");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getCategoryAndTagUrl", function (assert) {
|
test("getCategoryAndTagUrl", function (assert) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user