[FIX] website: traceback on non html page set as a link

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) <jke@openerp.com>
This commit is contained in:
Dhruv Patel
2021-07-23 17:23:07 +00:00
committed by Jeremy Kersten
parent 3b14eee027
commit 0b911fe04a
+8 -3
View File
@@ -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 [];
});
}