mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:59:51 +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 ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
import { searchForTerm } from "discourse/lib/search";
|
import { searchForTerm } from "discourse/lib/search";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
import { prefixProtocol } from "discourse/lib/url";
|
||||||
|
|
||||||
export default Controller.extend(ModalFunctionality, {
|
export default Controller.extend(ModalFunctionality, {
|
||||||
_debounced: null,
|
_debounced: null,
|
||||||
|
@ -144,8 +145,7 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
actions: {
|
actions: {
|
||||||
ok() {
|
ok() {
|
||||||
const origLink = this.linkUrl;
|
const origLink = this.linkUrl;
|
||||||
const linkUrl =
|
const linkUrl = prefixProtocol(origLink);
|
||||||
origLink.indexOf("://") === -1 ? `http://${origLink}` : origLink;
|
|
||||||
const sel = this.toolbarEvent.selected;
|
const sel = this.toolbarEvent.selected;
|
||||||
|
|
||||||
if (isEmpty(linkUrl)) {
|
if (isEmpty(linkUrl)) {
|
||||||
|
|
|
@ -493,4 +493,10 @@ export function setURLContainer(container) {
|
||||||
setOwner(_urlInstance, container);
|
setOwner(_urlInstance, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function prefixProtocol(url) {
|
||||||
|
return url.indexOf("://") === -1 && url.indexOf("mailto:") !== 0
|
||||||
|
? "https://" + url
|
||||||
|
: url;
|
||||||
|
}
|
||||||
|
|
||||||
export default _urlInstance;
|
export default _urlInstance;
|
||||||
|
|
|
@ -24,8 +24,8 @@ test("add a hyperlink to a reply", async (assert) => {
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".d-editor-input").val(),
|
find(".d-editor-input").val(),
|
||||||
"This is a link to [Google](http://google.com)",
|
"This is a link to [Google](https://google.com)",
|
||||||
"adds link with url and text, prepends 'http://'"
|
"adds link with url and text, prepends 'https://'"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -43,7 +43,7 @@ test("add a hyperlink to a reply", async (assert) => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".d-editor-input").val(),
|
find(".d-editor-input").val(),
|
||||||
"Reset textarea contents.",
|
"Reset textarea contents.",
|
||||||
"adds link with url and text, prepends 'http://'"
|
"doesn’t insert anything after cancelling"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
@ -61,7 +61,7 @@ test("add a hyperlink to a reply", async (assert) => {
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".d-editor-input").val(),
|
find(".d-editor-input").val(),
|
||||||
"[Reset](http://somelink.com) textarea contents.",
|
"[Reset](https://somelink.com) textarea contents.",
|
||||||
"adds link to a selected text"
|
"adds link to a selected text"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, module } from "qunit";
|
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 { setPrefix } from "discourse-common/lib/get-url";
|
||||||
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
@ -80,3 +80,19 @@ test("routeTo with prefix", async (assert) => {
|
||||||
"it should navigate to the messages page"
|
"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