summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-04-27 13:59:49 +0000
committerXavier Morel <xmo@odoo.com>2020-04-27 13:59:49 +0000
commitf08b5d22a4a39c3cb83585947506c0550b36f972 (patch)
treecc8df410aa444f9c6f583a291d13b5bdbffc203c /addons/web/static/src/js/core
parent7b402c5e59282eb9100adede97e730cdc73da690 (diff)
[IMP] web: handling of escaping in literals
Handling of escapes (`\`) was performed during evaluation rather than parsing, so strings in the AST stored the escaped form (rather than the proper one), and _formatAST had to mess around in order to try and get it back into a semblance of relevance (especially as the AST would store the escaped string without delimiters). Fix: perform the escapes handling (aka normalisation) during tokenization where it belongs. This means the AST formatter can now just JSON.stringify the data. Until and unless we decide to produce a cpython-compliant repr (https://github.com/python/cpython/blob/0169d3003be3d072751dd14a5c84748ab63a249f/Objects/unicodeobject.c#L12902-L13006) which is unlikely. closes odoo/odoo#50236 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/py_utils.js10
1 files changed, 1 insertions, 9 deletions
diff --git a/addons/web/static/src/js/core/py_utils.js b/addons/web/static/src/js/core/py_utils.js
index b796523c1db..590d5e62fc6 100644
--- a/addons/web/static/src/js/core/py_utils.js
+++ b/addons/web/static/src/js/core/py_utils.js
@@ -419,15 +419,7 @@ function _formatAST(ast, lbp) {
case "(number)":
return String(ast.value);
case "(string)":
- // ast.value is a string that may contain a mix of single and double quotes.
- // But we need to return a string that represents the string ast.value.
- // We use for that JSON.stringify. It will return a string with quotes correctly
- // escaped. For instance, for x = `""` JSON.stringify(x) is `"\"\""`.
- // But this means that if we pass several times here, escapes will be
- // done again and again, leading to a profusion of backslashes that we don't want.
- // For fun consider y = `\\` and y = JSON.stringify(y).
- // This is why we first deescape particular characters in ast.value.
- return JSON.stringify(ast.value.replace(/(\\(['"\\]))/g,"\$2"));
+ return JSON.stringify(ast.value);
case "(constant)":
return ast.value;
case "(name)":