diff --git a/addons/web_editor/static/src/js/editor/image_processing.js b/addons/web_editor/static/src/js/editor/image_processing.js index 4c70a827802..2c688b62ca3 100644 --- a/addons/web_editor/static/src/js/editor/image_processing.js +++ b/addons/web_editor/static/src/js/editor/image_processing.js @@ -447,11 +447,24 @@ export async function loadImageInfo(img, rpc, attachmentSrc = '') { return; } - const {original} = await rpc('/web_editor/get_image_info', {src: src.split(/[?#]/)[0]}); - // Check that url is local. - const isLocal = original && new URL(original.image_src, window.location.origin).origin === window.location.origin - && !/\/web\/image\/\d+-redirect\//.test(original.image_src); - if (isLocal && original.image_src) { + // Only consider the "relative" part of the URL. Needed because some + // relative URLs were wrongly converted to absolute URLs at some point and + // user domains could have been changed meanwhile. + let relativeSrc; + try { + const srcUrl = new URL(src); + relativeSrc = srcUrl.pathname; + } catch { + relativeSrc = src; + } + const {original} = await rpc('/web_editor/get_image_info', {src: relativeSrc.split(/[?#]/)[0]}); + // If src was an absolute "external" URL, we consider unlikely that its + // relative part matches something from the DB and even if it does, nothing + // bad happens, besides using this random image as the original when using + // the options, instead of having no option. + // The "redirect" check is for when it is a redirect image attachment due to + // an external URL upload. + if (original && original.image_src && !/\/web\/image\/\d+-redirect\//.test(original.image_src)) { img.dataset.originalId = original.id; img.dataset.originalSrc = original.image_src; img.dataset.mimetype = original.mimetype;