diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 5ba5e514834..319013c3194 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -805,10 +805,10 @@ function stripHistoryIds(value) { return value && value.replace(/\sdata-last-history-steps="[^"]*?"/, '') || value; } -// Ensure all external links are opened in a new tab. +// Ensure all links are opened in a new tab. const retargetLinks = (container) => { - for (const externalLink of container.querySelectorAll(`a:not([href^="${location.origin}"]):not([href^="/"])`)) { - externalLink.setAttribute('target', '_blank'); - externalLink.setAttribute('rel', 'noreferrer'); + for (const link of container.querySelectorAll('a')) { + link.setAttribute('target', '_blank'); + link.setAttribute('rel', 'noreferrer'); } } diff --git a/addons/web_editor/static/tests/html_field_tests.js b/addons/web_editor/static/tests/html_field_tests.js index ee6ebb26c59..a77472e760b 100644 --- a/addons/web_editor/static/tests/html_field_tests.js +++ b/addons/web_editor/static/tests/html_field_tests.js @@ -252,4 +252,33 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { assert.containsOnce(target, '.o_field_html[name="txt"] iframe[sandbox="allow-same-origin allow-popups allow-popups-to-escape-sandbox"]'); }); + QUnit.module('Readonly mode'); + + QUnit.test("Links should open on a new tab", async (assert) => { + assert.expect(6); + serverData.models.partner.records = [{ + id: 1, + txt: ` +
+ Relative link + Internal link + External link + `, + }]; + await makeView({ + type: "form", + resId: 1, + resModel: "partner", + serverData, + arch: ` + `, + }); + + for (const link of target.querySelectorAll('a')) { + assert.strictEqual(link.getAttribute('target'), '_blank'); + assert.strictEqual(link.getAttribute('rel'), 'noreferrer'); + } + }); });