Skip to content

Commit 1473ec2

Browse files
emge-odoorobinlej
authored andcommitted
[FIX] html_builder: error message for invalid URL
1 parent c1719df commit 1473ec2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

addons/html_builder/static/src/website_preview/website_builder_action.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ export class WebsiteBuilder extends Component {
309309
if (href && target !== "_blank" && !this.state.isEditing) {
310310
if (isTopWindowURL(linkEl)) {
311311
ev.preventDefault();
312-
browser.location.assign(href);
312+
try {
313+
browser.location.assign(href);
314+
} catch {
315+
this.notification.add(_t("%s is not a valid URL.", href), {
316+
title: _t("Invalid URL"),
317+
type: "danger",
318+
});
319+
}
313320
} else if (
314321
this.websiteContent.el.contentWindow.location.pathname !==
315322
new URL(href).pathname

addons/html_editor/static/src/main/link/link_popover.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ export class LinkPopover extends Component {
194194
) {
195195
url = "https://" + url;
196196
}
197+
if (url && (url.startsWith("http:") || url.startsWith("https:"))) {
198+
url = URL.parse(url) ? url : "";
199+
}
197200
return url;
198201
}
199202
deduceUrl(text) {
@@ -228,7 +231,6 @@ export class LinkPopover extends Component {
228231
this.state.previewIcon = { type: "mimetype", value: mimetype };
229232
return;
230233
}
231-
232234
try {
233235
url = new URL(this.state.url); // relative to absolute
234236
} catch {

0 commit comments

Comments
 (0)