A false result of a boolean helper is interpreted as a truthy "False" string.
Test case:
{{#if (Regex.IsMatch "a" "b")}}
TRUE
{{else}}
FALSE
{{/if}}
This prints TRUE; we should expect FALSE.
(Regex.IsMatch taken from https://github.com/StefH/Handlebars.Net.Helpers/wiki/Regex#ismatch .)
IsMatch correctly evaluates the regex match as (bool) False and prints it to the text writer. Then the sub-expression handler pulls it out as the "False" string and hands it over to the built-in "#if". The "#if" expects a boolean value so it runs HandlebarsUtils.IsTruthyOrNonEmpty("False") which evaluates it as true.
I believe "False" should evaluate to false, especially if produced by a boolean expression. The user shouldn't be affected by the fact that Handlebars.Net converts the value to string first (and pulls it out using CaptureTextWriterOutputFromHelper()).
For comparison, this works fine in JS:
handlebars.registerHelper('soBoolean', () => false);
const boolTemplate = handlebars.compile('{{#if (soBoolean)}}TRUE{{else}}FALSE{{/if}}');
console.log(boolTemplate()); // TRUE
The easy fix is to change IsFalsy() to perform Boolean.TryParse() for string values.
We might also want to consider my earlier suggestion that helpers should return value rather than print it to the text writer.
A false result of a boolean helper is interpreted as a truthy
"False"string.Test case:
This prints TRUE; we should expect FALSE.
(
Regex.IsMatchtaken from https://github.com/StefH/Handlebars.Net.Helpers/wiki/Regex#ismatch .)IsMatchcorrectly evaluates the regex match as(bool) Falseand prints it to the text writer. Then the sub-expression handler pulls it out as the"False"string and hands it over to the built-in "#if". The "#if" expects a boolean value so it runsHandlebarsUtils.IsTruthyOrNonEmpty("False")which evaluates it astrue.I believe
"False"should evaluate tofalse, especially if produced by abooleanexpression. The user shouldn't be affected by the fact that Handlebars.Net converts the value to string first (and pulls it out usingCaptureTextWriterOutputFromHelper()).For comparison, this works fine in JS:
The easy fix is to change
IsFalsy()to performBoolean.TryParse()for string values.We might also want to consider my earlier suggestion that helpers should return value rather than print it to the text writer.