Skip to content

Commit 55423d5

Browse files
committed
[FIX] html_builder: error message for invalid URL
1 parent bcc4933 commit 55423d5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ export class WebsiteBuilder extends Component {
191191
return;
192192
}
193193

194-
if (!isHTTPSorNakedDomainRedirection(iframe.contentWindow.location.origin, window.location.origin)) {
194+
if (
195+
!isHTTPSorNakedDomainRedirection(
196+
iframe.contentWindow.location.origin,
197+
window.location.origin
198+
)
199+
) {
195200
// If another domain ends up loading in the iframe (for example,
196201
// if the iframe is being redirected and has no initial URL, so it
197202
// loads "about:blank"), do not push that into the history
@@ -280,7 +285,14 @@ export class WebsiteBuilder extends Component {
280285
if (href && target !== "_blank" && !this.state.isEditing) {
281286
if (isTopWindowURL(linkEl)) {
282287
ev.preventDefault();
283-
browser.location.assign(href);
288+
try {
289+
browser.location.assign(href);
290+
} catch {
291+
this.notification.add(`"${href}" ${_t("is not a valid URL.")}`, {
292+
title: _t("Invalid URL"),
293+
type: "danger",
294+
});
295+
}
284296
} else if (
285297
this.websiteContent.el.contentWindow.location.pathname !==
286298
new URL(href).pathname

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

+3-1
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)