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
8 changes: 8 additions & 0 deletions Fluid.Tests/TemplateContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public void CaptureShouldUpdateContext()
Assert.Contains("greetings", context.ValueNames);
}

[Fact]
public void ScopeSetValueAcceptsNull()
{
var context = new TemplateContext();
context.SetValue("text", null);
Assert.Equal(NilValue.Instance, context.GetValue("text"));
}

private class TestClass
{
public string Name { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Fluid/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void SetValue(string name, FluidValue value)
{
_properties ??= new Dictionary<string, FluidValue>();

_properties[name] = value;
_properties[name] = value ?? NilValue.Instance;
}

public Scope EnterChildScope(Scope parent = null)
Expand Down
5 changes: 5 additions & 0 deletions Fluid/TemplateContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public static TemplateContext SetValue(this TemplateContext context, string name

public static TemplateContext SetValue(this TemplateContext context, string name, object value)
{
if (value == null)
{
return context.SetValue(name, NilValue.Instance);
}

return context.SetValue(name, FluidValue.Create(value, context.Options));
}

Expand Down