Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Object filter(
return object;
}

return defaultValue instanceof PyWrapper
return (defaultValue instanceof PyWrapper) || (defaultValue == null)
? defaultValue
: Objects.toString(defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,26 @@ public void itIgnoresBadTruthyValue() {
)
.isEqualTo("Type = str");
}

@Test
public void itDefaultsNullToNull() {
assertThat(
jinjava.render(
"{% set d=d | default(null) %}{% if (d == null) %}default yields real null{% else %}default yields something other than null{% endif %}",
new HashMap<>()
)
)
.isEqualTo("default yields real null");
}

@Test
public void itDefaultsNullToNullWithTruthyParam() {
assertThat(
jinjava.render(
"{% set d=d | default(null, true) %}{% if (d == null) %}default with truthy yields real null{% else %}default with truthy yields something other than null{% endif %}",
new HashMap<>()
)
)
.isEqualTo("default with truthy yields real null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public void testBool() {
public void testSafeString() {
assertThat(TypeFunction.type(new SafeString("foo"))).isEqualTo("str");
}

@Test
public void testNull() {
assertThat(TypeFunction.type(null)).isEqualTo("null");
}
}