Opened 10 years ago

Closed 10 years ago

#8517 closed defect (fixed)

dojo.addClass: check if classStr provided

Reported by: Les Owned by: anonymous
Priority: high Milestone: 1.3
Component: General Version: 1.2.3
Keywords: Cc:
Blocked By: Blocking:

Description

I noticed that dojo.addClass, removeClass... don't check if the classStr parameter was provided.

If, for example, I add an undefined classStr to a tree icon node, the iconNode.className property will appear as "dijitInline dijitTreeIcon TreeIconReport? undefined".

I think, it would be better if in this example the 'undefined' class name was not added.

Change History (4)

comment:1 Changed 10 years ago by bill

I've noticed this too but it seems like a bug in the Tree code. Isn't calling dojo.addClass() without a class an error? It's not an optional parameter.

comment:2 in reply to:  1 Changed 10 years ago by Les

This would happen if the user overridden functions getIconClass() or getLabelClass() didn't return a value (class string). So perhaps the Tree code could be modified to compensate for the lack of returned value in these functions, see below:

this._iconClass = tree.getIconClass(item, this.isExpanded) || '';
this._labelClass = tree.getLabelClass(item, this.isExpanded) || '';

comment:3 Changed 10 years ago by bill

(In [16504]) Don't pass null or undefined argument to addClass(). Refs #8517 !strict.

comment:4 Changed 10 years ago by dante

Milestone: tbd1.3
Resolution: fixed
Status: newclosed

classStr is a required parameter. The developer should ensure defined values are being passed, as bill handled in [16504]. I don't think the extra few bytes in base would be worthwhile here, but please reopen if strongly opposed.

Note: See TracTickets for help on using tickets.