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) {
|
||||
return !url.includes("://") && !url.startsWith("mailto:")
|
||||
? "https://" + url
|
||||
: url;
|
||||
if (!url || typeof url !== "string") {
|
||||
return 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) {
|
||||
|
|
|
@ -184,6 +184,15 @@ module("Unit | Utility | url", function (hooks) {
|
|||
prefixProtocol("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) {
|
||||
|
|
Loading…
Reference in New Issue