Skip to content

[FIX] html_builder: error message for invalid URL #4601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion addons/html_editor/static/src/main/link/link_popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down