From: Xavier Morel Date: Tue, 14 Oct 2014 14:17:04 +0000 (+0200) Subject: [FIX] implementation of t-call's 0-index in qweb-js X-Git-Tag: InsPy_8.0_01~4^2~6 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=b9fdb93bece59c1d3d8cf17495e9f9f0d90e6b23;p=odoo%2Fodoo.git [FIX] implementation of t-call's 0-index in qweb-js Had expected regularity, had not noticed the Python version is really an ignoble hack where the string "0" (exactly) is interpreted in a specific manner when used in t-raw and format strings, *and nowhere else*. Had special-cased the expression everywhere which broke e.g. . Reproduce Python behavior more closely, and strongly consider swapping out both for something different e.g. [[content]] or something like that, which doesn't cause problems in Python but doesn't have to be so specially cased either. --- diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index c845abd..0994ae2 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -26,12 +26,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // TODO: templates orverwritten could be called by t-call="__super__" ? // TODO: t-set + t-value + children node == scoped variable ? var QWeb2 = { - expressions_cache: { - // special case for template bodies, __content__ doesn't work in - // Python impl because safe_eval -> assert_no_dunder_name so use - // Python impl's magical 0 variable instead - '0': 'dict[0]', - }, + expressions_cache: { }, RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','), ACTIONS_PRECEDENCE: 'foreach,if,call,set,esc,raw,js,debug,log'.split(','), WORD_REPLACEMENT: { @@ -594,6 +589,12 @@ QWeb2.Element = (function() { QWeb2.expressions_cache[e] = r; return r; }, + format_str: function (e) { + if (e == '0') { + return 'dict[0]'; + } + return this.format_expression(e); + }, string_interpolation : function(s) { var _this = this; if (!s) { @@ -608,7 +609,7 @@ QWeb2.Element = (function() { // extract literal string between previous and current match append_literal(s.slice(start, re.lastIndex - m[0].length)); // extract matched expression - r.push('(' + this.format_expression(m[2] || m[1]) + ')'); + r.push('(' + this.format_str(m[2] || m[1]) + ')'); // update position of new matching start = re.lastIndex; } @@ -737,7 +738,7 @@ QWeb2.Element = (function() { + "));"); }, compile_action_raw : function(value) { - this.top("r.push(" + (this.format_expression(value)) + ");"); + this.top("r.push(" + (this.format_str(value)) + ");"); }, compile_action_js : function(value) { this.top("(function(" + value + ") {");