Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#17259 closed defect (invalid)

DTL: error when path resolves to null

Reported by: mlohbihler Owned by:
Priority: undecided Milestone: tbd
Component: DojoX DTL Version: 1.9.0
Keywords: Cc:
Blocked By: Blocking:

Description

When the DTL path resolves to a null value in the context, the error "str is null" is thrown. A patch for this is below. It handles all invalid values of str, not just null. (It's debatable that a value of "undefined" should still throw an error.)

Patch:

### Eclipse Workspace Patch 1.0 #P dojox-dtl Index: _base.js =================================================================== --- _base.js (revision 31452) +++ _base.js (working copy) @@ -549,7 +549,9 @@

{

render: function(context, buffer){

var str = this.contents.resolve(context);

  • if(!str.safe){

+ if (!str) + str = ""; + else if(!str.safe){

str = dd._base.escape("" + str);

} return buffer.concat(str);

Change History (5)

comment:1 Changed 7 years ago by mlohbihler

Unformatted version of the patch:

### Eclipse Workspace Patch 1.0
#P dojox-dtl
Index: _base.js
===================================================================
--- _base.js	(revision 31452)
+++ _base.js	(working copy)
@@ -549,7 +549,9 @@
 	{
 		render: function(context, buffer){
 			var str = this.contents.resolve(context);
-			if(!str.safe){
+			if (!str)
+				str = "";
+			else if(!str.safe){
 				str = dd._base.escape("" + str);
 			}
 			return buffer.concat(str);

comment:2 Changed 7 years ago by mlohbihler

Discovered the "default" filter. Please disregard.

comment:3 Changed 7 years ago by mlohbihler

Although i might suggest providing a better error message, maybe one that includes the original path. Just "str is null" makes it difficult to track down the source of the problem.

comment:4 Changed 7 years ago by ben hockey

Resolution: invalid
Status: newclosed

closing as requested

comment:5 in reply to:  4 Changed 6 years ago by baycik

Replying to neonstalwart:

closing as requested

I think this ticket should not be closed. The "str is null" error is really annoying and mapping null values to empty string is very natural behavior. "default" filter make template hard to read and write so it is not the solution.

Note: See TracTickets for help on using tickets.