Skip to content

Treat nil and empty binaries as false in conditions#51

Merged
soranoba merged 3 commits into
soranoba:masterfrom
bjyoungblood:nil-and-empty-string-as-false
Oct 15, 2020
Merged

Treat nil and empty binaries as false in conditions#51
soranoba merged 3 commits into
soranoba:masterfrom
bjyoungblood:nil-and-empty-string-as-false

Conversation

@bjyoungblood

Copy link
Copy Markdown
Contributor

First, thanks for creating this library! Second, please forgive me -- I work mainly with Elixir, and this is the first time I've written any Erlang. If you have any suggestions on how I can improve this, please let me know.


Most Mustache implementations that I've used in other languages treat "" and nil/null/undefined the same as false in conditions. For example, if you plug this template into https://mustache.github.io/#demo

{{#test1}}
aaa
{{/test1}}
{{^test1}}
bbb
{{/test1}}

{{#test2}}
ccc
{{/test2}}
{{^test2}}
ddd
{{/test2}}

and put {"test1": "", "test2": null} into the JSON field, it should render this:

bbb
ddd

Comment thread src/bbmustache.erl Outdated
Comment thread src/bbmustache.erl
Result, Value), State);
_ when Value =:= false ->
compile_impl(T, Data, Result, State);
_ when Value =:= nil ->

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Elixer commonly use nil?
If so, please provide links that it can refer to.

NULL has various notations depending on the language, so I think that it will necessary to consider the validity.

@bjyoungblood bjyoungblood Oct 15, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Elixir's nil is equivalent to NULL (at least in most languages I'm familiar with). https://hexdocs.pm/elixir/Kernel.html#module-truthy-and-falsy-values

Co-authored-by: Hinagiku Soranoba <soranoba@gmail.com>
@soranoba soranoba merged commit f52705a into soranoba:master Oct 15, 2020
@soranoba

Copy link
Copy Markdown
Owner

Thank you for your contribution.
I made some modifications and merge them at #52 .

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

Successfully merging this pull request may close these issues.

2 participants