Opened 12 years ago
Closed 11 years ago
#5226 closed defect (fixed)
dijit._Templated does not replace booleans correctly
Reported by: | guest | Owned by: | Adam Peller |
---|---|---|---|
Priority: | high | Milestone: | 1.2 |
Component: | Dijit | Version: | 1.0 |
Keywords: | Cc: | ptwobrussell@… | |
Blocked By: | Blocking: |
Description (last modified by )
If a widget contains e.g:
myBool: false
and your template contains:
<div dojoType="myWidget" value="${myBool}"></div>
value is evaluated to true.
This happened after changeset r10979 when the following was added on line 64 in the buildRendering function:
if(!value){ return ""; }
The buildRendering function now replaces ${myBool} with "" instead of "false".
After this the str2obj function is called in the dojo parser. In the boolean case the following code is run:
return typeof value == "boolean" ? value : !(value.toLowerCase()=="false");
Since value is "" it returns true.
Regards, Thomas
Attachments (1)
Change History (20)
comment:1 Changed 12 years ago by
Owner: | set to alex |
---|
comment:2 Changed 12 years ago by
comment:4 Changed 12 years ago by
Milestone: | 1.0.2 → 1.0.3 |
---|
comment:5 Changed 12 years ago by
Status: | new → assigned |
---|
comment:6 Changed 12 years ago by
Milestone: | 1.0.3 → 1.1 |
---|
comment:7 Changed 12 years ago by
Priority: | highest → normal |
---|
comment:8 Changed 12 years ago by
Milestone: | 1.1 → 1.2 |
---|
Move all milestone 1.1 tickets to 1.2, except for reopened tickets and tickets opened after 1.1RC1 was released.
Changed 12 years ago by
A test case illustrating the behavior - useful to illustrate the bug.
comment:9 Changed 12 years ago by
Cc: | ptwobrussell@… added |
---|---|
Description: | modified (diff) |
comment:10 Changed 11 years ago by
Milestone: | 1.2 → 1.4 |
---|---|
Owner: | changed from alex to bill |
Status: | assigned → new |
comment:11 Changed 11 years ago by
Maybe this is the patch? Seems to make sense and works on the test case provided.
Index: _Templated.js =================================================================== --- _Templated.js (revision 14945) +++ _Templated.js (working copy) @@ -43,7 +43,7 @@ return dojo.string.substitute(tmpl, this, function(value, key){ if(key.charAt(0) == '!'){ value = _this[key.substr(1)]; } if(typeof value == "undefined"){ throw new Error(className+" template:"+key); } // a debugging aide - if(!value){ return ""; } + if(value === ""){ return ""; } // Substitution keys beginning with ! will skip the transform step, // in case a user wishes to insert unescaped markup, e.g. ${!foo}
comment:12 Changed 11 years ago by
I think the issue is that when value isn't a string (like when it's a boolean) then the .charAt() on the next line fails, at least on some browsers.
comment:13 Changed 11 years ago by
Oops, I meant toString(), not charAt(). My point is that your patch reverts the behavior to as it was before [10979], but presumably there's some reason Alex changed that.
comment:14 Changed 11 years ago by
only thing I think needs to be safeguarded is a null check. perhaps that's what was intended. would it be more appropriate to return "" or throw as with undefined? need to test against the test case in #4643 on IE, I guess.
comment:15 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:16 Changed 11 years ago by
Milestone: | 1.4 → 1.2 |
---|
comment:17 Changed 11 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
The test case added above fails on IE. It assume DOM node attributes appear in a certain order (<span num="-5" value="true">
) but IE prints them in the opposite order.
Also another error after that I didn't track down.
comment:18 Changed 11 years ago by
Owner: | changed from bill to Adam Peller |
---|---|
Status: | reopened → new |
comment:19 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Is this problem specific to the parameter named "value" (which is special, btw), or does it happen with any parameter name?