Ticket #5226 (closed defect: fixed)

Opened 20 months ago

Last modified 9 months ago

dijit._Templated does not replace booleans correctly

Reported by: guest Owned by: peller
Priority: normal Milestone: 1.2
Component: Dijit Version: 1.0
Severity: critical Keywords:
Cc: ptwobrussell@…

Description (last modified by ptwobrussell) (diff)

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

foo.html (1.2 kB) - added by ptwobrussell 14 months ago.
A test case illustrating the behavior - useful to illustrate the bug.

Change History

Changed 20 months ago by peller

  • owner set to alex

Changed 19 months ago by bill

Is this problem specific to the parameter named "value" (which is special, btw), or does it happen with any parameter name?

Changed 19 months ago by guest

It happens with any parameter name.

Changed 19 months ago by peller

  • milestone changed from 1.0.2 to 1.0.3

Changed 19 months ago by alex

  • status changed from new to assigned

Changed 17 months ago by dylan

  • milestone changed from 1.0.3 to 1.1

Changed 16 months ago by bill

  • priority changed from highest to normal

Changed 16 months ago by bill

  • milestone changed from 1.1 to 1.2

Move all milestone 1.1 tickets to 1.2, except for reopened tickets and tickets opened after 1.1RC1 was released.

Changed 14 months ago by ptwobrussell

A test case illustrating the behavior - useful to illustrate the bug.

Changed 14 months ago by ptwobrussell

  • cc ptwobrussell@… added
  • description modified (diff)

Changed 10 months ago by bill

  • owner changed from alex to bill
  • status changed from assigned to new
  • milestone changed from 1.2 to 1.4

Changed 10 months ago by ptwobrussell

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}

Changed 10 months ago by bill

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.

Changed 10 months ago by bill

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.

Changed 10 months ago by peller

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.

Changed 10 months ago by peller

  • status changed from new to closed
  • resolution set to fixed

(In [15166]) Fixes #5226, regression of boolean attribute handling in _Templated. Thanks, ptwobrussell! Refs #4643

Changed 10 months ago by peller

  • milestone changed from 1.4 to 1.2

Changed 9 months ago by bill

  • status changed from closed to reopened
  • resolution deleted

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.

Changed 9 months ago by bill

  • owner changed from bill to peller
  • status changed from reopened to new

Changed 9 months ago by peller

  • status changed from new to closed
  • resolution set to fixed

(In [15328]) Fix tests on IE. Fixes #5226. Tag attribute order is unspecified.

Note: See TracTickets for help on using tickets.