Skip to content

Commit

Permalink
Merge pull request #1008 from dbyron-sf/issue-429
Browse files Browse the repository at this point in the history
fix(default): change default(null) to return null instead of "null"
  • Loading branch information
jasmith-hs authored Mar 14, 2023
2 parents e4ce11a + d733fdf commit 189046b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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");
}
}

0 comments on commit 189046b

Please sign in to comment.