[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
This commit is contained in:
Nicolas Lempereur
2018-02-20 12:25:54 +01:00
parent bd16df15ea
commit 64be3521ce
@@ -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);
}
/**