From 64be3521cefb1e71047a04e4d05c20308040a2dd Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 19 Feb 2018 17:09:02 +0100 Subject: [PATCH] [FIX] web_editor: don't format xml with script tag It happens from time to time that someone use "Format" on the web.layout template. Thus: ``` ``` becomes: ``` ``` breaking a number of things on the frontend and everything on the backend. On a pure javascript content, we could wrap it with: ``` // ``` but in this instance we still want the xml to be processed. This commit avoids formatting XML containing a script tag. opw-815865 closes #23164 --- addons/web_editor/static/src/js/widgets/ace.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/web_editor/static/src/js/widgets/ace.js b/addons/web_editor/static/src/js/widgets/ace.js index 0a89d0d8ce7..64502b41c31 100644 --- a/addons/web_editor/static/src/js/widgets/ace.js +++ b/addons/web_editor/static/src/js/widgets/ace.js @@ -58,6 +58,10 @@ function checkXML(xml) { * @returns {string} formatted xml */ function formatXML(xml) { + // do nothing if an inline script is present to avoid breaking it + if (/]*)?>[^<][\s\S]*<\/script>/i.test(xml)) { + return xml; + } return window.vkbeautify.xml(xml, 4); } /**