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
9 changes: 9 additions & 0 deletions Fluid.Tests/StringValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ public void CreateStringValue(string value, string expected, bool isEmpty)
Assert.Equal(expected, stringValue.ToStringValue());
Assert.Equal(isEmpty, stringValue.Equals(StringValue.Empty));
}

[Fact]
public void StringValueCreateNullShouldReturnEmpty()
{
var stringValue = new StringValue(null);

// Assert
Assert.Equal(StringValue.Empty, stringValue);
}
}
}
15 changes: 12 additions & 3 deletions Fluid/Values/StringValue.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using Parlot;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Encodings.Web;
using Parlot;

namespace Fluid.Values
{
Expand All @@ -27,6 +27,9 @@ static StringValue()

public StringValue(string value)
{
// Returns a StringValue instance and not NilValue since this is what is asked for.
// However FluidValue.Create(null) returns NilValue.

_value = value ?? NilValue.Instance.ToStringValue();
}

Expand Down Expand Up @@ -56,7 +59,7 @@ internal static StringValue Create(char c)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static StringValue Create(string s)
{
if (s == "")
if (String.IsNullOrEmpty(s))
{
return Empty;
}
Expand All @@ -66,6 +69,12 @@ public static StringValue Create(string s)
: new StringValue(s);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static StringValue Create(string s, bool encode)
{
return Create(s, encode);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static StringValue Create(in TextSpan span)
{
Expand Down