Opened 14 years ago

Closed 14 years ago

#3700 closed defect (fixed)

dijit._Template: weird error if template variable value is not defined.

Reported by: James Burke Owned by: Adam Peller
Priority: high Milestone: 0.9
Component: Dijit Version: 0.9
Keywords: Cc:
Blocked By: Blocking:


I got a "_5 has no properties" error when using a templated widget that had a ${variable} in it that was not found via dojo.string.substitute's getObject call:

value = dojo.getObject(format,false,thisObject)(value);}

value ended up being null (or undefined, or not a string), and this bad value was passed to the "transform" function in dojo.string.substitute, which in dijit._Templated's case was this function (inside buildRendering function:

var tstr = dojo.string.substitute(cached, this, function(value){
  // Safer substitution, see heading "Attribute values" in
  return value.toString().replace(/"/g,"""); //TODO: support a more complete set of escapes?
}, this);

Operating on the bad value inside of this function caused the problem. So maybe make this anonymous function aware of bad substitute values and/or make dojo.string.substitute return an empty string for values not found via the dojo.getObject() call?

Change History (6)

comment:1 Changed 14 years ago by bill

Milestone: 0.9
Owner: changed from bill to Adam Peller

comment:2 Changed 14 years ago by James Burke

Another option might be to warn the user that a substitution could not be made. I overrode the dojo.string.substitute method and put in a warning to help find the original problem.

comment:3 Changed 14 years ago by Adam Peller

I tried writing that method to be very compact and just throw an exception naturally (but predictably) w/o putting in any special conditionals or error messages... The new transform step really does obfuscate things. I'll take another look at what we can do to make this more friendly.

comment:4 Changed 14 years ago by Adam Peller

Resolution: fixed
Status: newclosed

(In [9629]) Put a more descriptive throw in _Templated for missing keys. Don't want to just return an empty string, or the developer may never notice the error. Also allow user to use HTML literals in templates using "!" prefix. Fixes #3700

comment:5 Changed 14 years ago by bill

Resolution: fixed
Status: closedreopened

In [9632] I reverted the previous change ([9629]). It broke many of the widget tests including test_Button.html. "" is not an invalid value for a string. Also need to print the widget's id or at least declaredClass in the error message.

comment:6 Changed 14 years ago by Adam Peller

Resolution: fixed
Status: reopenedclosed

(In [9642]) Sorry about that. Really fixes #3700 this time.

Note: See TracTickets for help on using tickets.