Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short-circuit Problem With SafeString Using or (And Maybe Other Helper) #146

Open
markusm7 opened this issue Apr 27, 2022 · 0 comments
Open

Comments

@markusm7
Copy link

markusm7 commented Apr 27, 2022

In our app we used the or-helper in a template condition with two parameters, the first a SafeString (created with htmlSafe) and the other a tracked local property.

{{#if (or @safeString this.trackedProperty)}}
... awesome application html
{{/if}}

The problem we faced is that since the @safeString is always an object (even if its an empty string) the or evaluates to true for it, but the ìf handles an empty safe string object properly and doesnt evaluate to true. This causes to never evaluate the second param, no matter if it changes to a "more truthy" value than the empty safe string. Is this something that should be changed or does it work as intended and should be addressed by the application? My problem with it is, that it handles htmlSafe in another way as the ìf-helper does.

At the moment we just simply add checks for the string before we create our SafeString, e.g.:

const safeString = isEmpty(maybeHtml) ? '' : htmlSafe(maybeHtml);

This way the or checks on a normal empty string, which evaluates to false and therefore checks also the second param. Of course there are several other approaches like changing the order of the params, putting the or logic in a local getter and so on, but thats not part of my original question

@markusm7 markusm7 changed the title Short-circuit Poblem With SafeString Using or (And Maybe Other Helper) Short-circuit Problem With SafeString Using or (And Maybe Other Helper) Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant