diff --git a/addons/html_builder/static/src/website_preview/website_builder_action.js b/addons/html_builder/static/src/website_preview/website_builder_action.js
index f8dda38165ac6..c2fd3c948cada 100644
--- a/addons/html_builder/static/src/website_preview/website_builder_action.js
+++ b/addons/html_builder/static/src/website_preview/website_builder_action.js
@@ -191,7 +191,12 @@ export class WebsiteBuilder extends Component {
return;
}
- if (!isHTTPSorNakedDomainRedirection(iframe.contentWindow.location.origin, window.location.origin)) {
+ if (
+ !isHTTPSorNakedDomainRedirection(
+ iframe.contentWindow.location.origin,
+ window.location.origin
+ )
+ ) {
// If another domain ends up loading in the iframe (for example,
// if the iframe is being redirected and has no initial URL, so it
// loads "about:blank"), do not push that into the history
@@ -280,7 +285,14 @@ export class WebsiteBuilder extends Component {
if (href && target !== "_blank" && !this.state.isEditing) {
if (isTopWindowURL(linkEl)) {
ev.preventDefault();
- browser.location.assign(href);
+ try {
+ browser.location.assign(href);
+ } catch {
+ this.notification.add(_t("%s is not a valid URL.", href), {
+ title: _t("Invalid URL"),
+ type: "danger",
+ });
+ }
} else if (
this.websiteContent.el.contentWindow.location.pathname !==
new URL(href).pathname
diff --git a/addons/html_editor/static/src/main/link/link_popover.js b/addons/html_editor/static/src/main/link/link_popover.js
index f359b9e4a994c..856ebbf24259a 100644
--- a/addons/html_editor/static/src/main/link/link_popover.js
+++ b/addons/html_editor/static/src/main/link/link_popover.js
@@ -194,6 +194,9 @@ export class LinkPopover extends Component {
) {
url = "https://" + url;
}
+ if (url && (url.startsWith("http:") || url.startsWith("https:"))) {
+ url = URL.parse(url) ? url : "";
+ }
return url;
}
deduceUrl(text) {
@@ -228,7 +231,6 @@ export class LinkPopover extends Component {
this.state.previewIcon = { type: "mimetype", value: mimetype };
return;
}
-
try {
url = new URL(this.state.url); // relative to absolute
} catch {