From 0b911fe04ae613dadbd07d6add99de5c86186e18 Mon Sep 17 00:00:00 2001 From: Dhruv Patel Date: Thu, 22 Jul 2021 05:02:53 +0000 Subject: [PATCH] [FIX] website: traceback on non html page set as a link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, when you add a link in any of the buttons on the website with non HTML/XML page, it will raise the traceback as we fetch the content to find id to propose as a list of anchors. Reproduction Steps: 1) Add a button on the website using the editor. 2) Add link in URL (i.e. /robots.txt) 3) Traceback With this commit, When you add the non HTML/XML page to any of the link will not raise the traceback. task-2596392 closes odoo/odoo#74194 X-original-commit: 5f78c19995cc6d1fe480b982176e0701bd4d3e86 Signed-off-by: Jérémy Kersten (jke) --- addons/website/static/src/js/utils.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index 18f75a9e673..977818a33ac 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -14,15 +14,20 @@ const { qweb, _t } = core; */ function loadAnchors(url) { return new Promise(function (resolve, reject) { - if (url !== window.location.pathname && url[0] !== '#') { - $.get(window.location.origin + url).then(resolve, reject); - } else { + if (url === window.location.pathname || url[0] === '#') { resolve(document.body.outerHTML); + } else if (url.length && !url.startsWith("http")) { + $.get(window.location.origin + url).then(resolve, reject); + } else { // avoid useless query + resolve(); } }).then(function (response) { return _.map($(response).find('[id][data-anchor=true]'), function (el) { return '#' + el.id; }); + }).catch(error => { + console.debug(error); + return []; }); }