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

Treat null values as falsey in inverted sections #63

Merged
merged 1 commit into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Mustache library changelog

## v2.4.1

- Also treat Null as falsey in inverted sections

## v2.4.0

- Support for aeson 2
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mustache
version: '2.4.0'
version: '2.4.1'
synopsis: A mustache template parser library.
description: ! 'Allows parsing and rendering template files with mustache markup.
See the
Expand Down
1 change: 1 addition & 0 deletions src/Text/Mustache/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ substituteNode (InvertedSection (NamedData secName) invSecSTree) =
search secName >>= \case
Just (Bool False) -> contents
Just (Array a) | V.null a -> contents
Just Null -> contents
Nothing -> contents
_ -> return ()
where
Expand Down
6 changes: 6 additions & 0 deletions test/unit/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ substituteSpec =
])
`shouldBe` "var1var2"

it "substitutes an inverse section when the key is present (and null)" $
substitute
(toTemplate [InvertedSection (NamedData ["section"]) [TextBlock "t"]])
(object ["section" ~> Null])
`shouldBe` "t"

it "does not substitute a section when the key is not present" $
substitute
(toTemplate [Section (NamedData ["section"]) [TextBlock "t"]])
Expand Down