-
Notifications
You must be signed in to change notification settings - Fork 12
Description
How often can you reproduce it?
- Always
- Sometimes
- Rarely
- Unable
- I didn’t try
Description:
When using an expression in stache that is supposed to render the result of a top-level not() call as a true or false string, e.g.
a basic aria-hidden="{{ not( this.expanded ) }}" as part of a disclosure widget, then the not converter will always render an empty string as a result.
The root cause is in broken logic in the not converter's getter:
Lines 496 to 507 in 17b727a
| var notConverter = { | |
| get: function(obs, options){ | |
| if(helpersCore.looksLikeOptions(options)) { | |
| return canReflect.getValue(obs) ? options.inverse() : options.fn(); | |
| } else { | |
| return !canReflect.getValue(obs); | |
| } | |
| }, | |
| set: function(newVal, obs){ | |
| canReflect.setValue(obs, !newVal); | |
| } | |
| }; |
It uses looksLikeOptions and then falsely (!!) assumes whenever an options argument is present, that the not converter is being used as a {{#not}} sectioning helper. This leads to cases such as the above example to effectively be interpreted as:
aria-hidden="{{#not ( this.expanded ) }}{{/not}}"
- i.e. to be interpreted as never rendering any actual content, because the sectioning templates are empty.
Here's also a screenshot of the above problem in action, with the debugger halted on the problematic conditional branch:

What the converter should be doing is strengthening that check with an additional check of the options.isSection property.
E.g.
var notConverter = {
get: function(obs, options){
if(helpersCore.looksLikeOptions(options) && (options.isSection !== false)) {
return canReflect.getValue(obs) ? options.inverse() : options.fn();
} else {
return !canReflect.getValue(obs);
}
},
set: function(newVal, obs){
canReflect.setValue(obs, !newVal);
}
};Steps to reproduce:
See the description.
Expected results:
The not converter handles the described case correctly and does not hit the sectioning helper logic branch.
Actual results:
The not converter handles the described case incorrectly and hits the sectioning helper logic branch.
Environment:
| Software | Version |
|---|---|
| can-stache version | all current affected |
| Browser | any |
| Operating system | any |