summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/widgets/ace.js
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2018-02-19 17:09:02 +0100
committerNicolas Lempereur <nle@odoo.com>2018-02-20 12:25:54 +0100
commit64be3521cefb1e71047a04e4d05c20308040a2dd (patch)
treee9ea5733e1c762989c3e10a90023268fe9dc1acb /addons/web_editor/static/src/js/widgets/ace.js
parentbd16df15ea6ce7d746e09a48909391c768694396 (diff)
[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: ``` <script type="text/javascript"> var odoo = { csrf_token: "<t t-esc="request.csrf_token(None)"/>", }; </script> ``` becomes: ``` <script type="text/javascript"> var odoo = { csrf_token: " <t t-esc="request.csrf_token(None)"/>", }; </script> ``` breaking a number of things on the frontend and everything on the backend. On a pure javascript content, we could wrap it with: ``` //<![CDATA[ /* javascript content */ //]]> ``` 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
Diffstat (limited to 'addons/web_editor/static/src/js/widgets/ace.js')
-rw-r--r--addons/web_editor/static/src/js/widgets/ace.js4
1 files changed, 4 insertions, 0 deletions
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 (/<script(?: [^>]*)?>[^<][\s\S]*<\/script>/i.test(xml)) {
+ return xml;
+ }
return window.vkbeautify.xml(xml, 4);
}
/**