mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
FIX: ensures insert hyperlink works with mailto (#10867)
The prefixing logic is moved into a `prefixProtocol` function in lib:url. This commit also renames an incorrectly named test and uses https as default instead of http, in 2020 it's reasonable to think we most likely want https and not http. User can still specify http if required.
This commit is contained in:
parent
c3e8bc0280
commit
8520096043
|
@ -4,6 +4,7 @@ import Controller from "@ember/controller";
|
|||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||
import { searchForTerm } from "discourse/lib/search";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import { prefixProtocol } from "discourse/lib/url";
|
||||
|
||||
export default Controller.extend(ModalFunctionality, {
|
||||
_debounced: null,
|
||||
|
@ -144,8 +145,7 @@ export default Controller.extend(ModalFunctionality, {
|
|||
actions: {
|
||||
ok() {
|
||||
const origLink = this.linkUrl;
|
||||
const linkUrl =
|
||||
origLink.indexOf("://") === -1 ? `http://${origLink}` : origLink;
|
||||
const linkUrl = prefixProtocol(origLink);
|
||||
const sel = this.toolbarEvent.selected;
|
||||
|
||||
if (isEmpty(linkUrl)) {
|
||||
|
|
|
@ -493,4 +493,10 @@ export function setURLContainer(container) {
|
|||
setOwner(_urlInstance, container);
|
||||
}
|
||||
|
||||
export function prefixProtocol(url) {
|
||||
return url.indexOf("://") === -1 && url.indexOf("mailto:") !== 0
|
||||
? "https://" + url
|
||||
: url;
|
||||
}
|
||||
|
||||
export default _urlInstance;
|
||||
|
|
|
@ -24,8 +24,8 @@ test("add a hyperlink to a reply", async (assert) => {
|
|||
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
"This is a link to [Google](http://google.com)",
|
||||
"adds link with url and text, prepends 'http://'"
|
||||
"This is a link to [Google](https://google.com)",
|
||||
"adds link with url and text, prepends 'https://'"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
|
@ -43,7 +43,7 @@ test("add a hyperlink to a reply", async (assert) => {
|
|||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
"Reset textarea contents.",
|
||||
"adds link with url and text, prepends 'http://'"
|
||||
"doesn’t insert anything after cancelling"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
|
@ -61,7 +61,7 @@ test("add a hyperlink to a reply", async (assert) => {
|
|||
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
"[Reset](http://somelink.com) textarea contents.",
|
||||
"[Reset](https://somelink.com) textarea contents.",
|
||||
"adds link to a selected text"
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { test, module } from "qunit";
|
||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||
import DiscourseURL, { userPath, prefixProtocol } from "discourse/lib/url";
|
||||
import { setPrefix } from "discourse-common/lib/get-url";
|
||||
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||
import User from "discourse/models/user";
|
||||
|
@ -80,3 +80,19 @@ test("routeTo with prefix", async (assert) => {
|
|||
"it should navigate to the messages page"
|
||||
);
|
||||
});
|
||||
|
||||
test("prefixProtocol", async (assert) => {
|
||||
assert.equal(
|
||||
prefixProtocol("mailto:mr-beaver@aol.com"),
|
||||
"mailto:mr-beaver@aol.com"
|
||||
);
|
||||
assert.equal(prefixProtocol("discourse.org"), "https://discourse.org");
|
||||
assert.equal(
|
||||
prefixProtocol("www.discourse.org"),
|
||||
"https://www.discourse.org"
|
||||
);
|
||||
assert.equal(
|
||||
prefixProtocol("www.discourse.org/mailto:foo"),
|
||||
"https://www.discourse.org/mailto:foo"
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user