From 686e695433573cd98d141570891052324646ae95 Mon Sep 17 00:00:00 2001 From: emge-odoo Date: Wed, 7 May 2025 16:19:43 +0200 Subject: [PATCH] [FIX] html_builder: error message for invalid URL --- .../website_preview/website_builder_action.js | 16 ++++++++++++++-- .../static/src/main/link/link_popover.js | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) 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 {