Skip to content

Commit

Permalink
Change tests that would fail if default for
Browse files Browse the repository at this point in the history
UseLegacyHandlebarsNetHtmlEncoding was set to false.
  • Loading branch information
tommysor committed Dec 20, 2021
1 parent 49610d7 commit a2dd13a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions source/Handlebars.Test/BasicIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class HandlebarsEnvGenerator : IEnumerable<object[]>

public class BasicIntegrationTests
{
private static string HtmlEncodeStringHelper(IHandlebars handlebars, string inputString)
{
using var stringWriter = new System.IO.StringWriter();
handlebars.Configuration.TextEncoder.Encode(inputString, stringWriter);
return stringWriter.ToString();
}

[Theory]
[ClassData(typeof(HandlebarsEnvGenerator))]
public void BasicEnumerableFormatter(IHandlebars handlebars)
Expand Down Expand Up @@ -98,7 +105,9 @@ public void BasicPathUnresolvedBindingFormatter(IHandlebars handlebars)
name = "Handlebars.Net"
};
var result = template(data);
Assert.Equal("Hello, ('foo' is undefined)!", result);

var expected = HtmlEncodeStringHelper(handlebars, "Hello, ('foo' is undefined)!");
Assert.Equal(expected, result);
}

[Theory, ClassData(typeof(HandlebarsEnvGenerator))]
Expand All @@ -114,7 +123,9 @@ public void PathUnresolvedBindingFormatter(IHandlebars handlebars)
name = "Handlebars.Net"
};
var result = template(data);
Assert.Equal("Hello, ('foo' is undefined)!", result);

var expected = HtmlEncodeStringHelper(handlebars, "Hello, ('foo' is undefined)!");
Assert.Equal(expected, result);
}

[Theory, ClassData(typeof(HandlebarsEnvGenerator))]
Expand Down Expand Up @@ -355,7 +366,9 @@ public void BasicPathRelativeDotBinding(IHandlebars handlebars)
nestedObject = "Relative dots, yay"
};
var result = template(data);
Assert.Equal("{ nestedObject = Relative dots, yay }", result);

var expected = HtmlEncodeStringHelper(handlebars, "{ nestedObject = Relative dots, yay }");
Assert.Equal(expected, result);
}

[Theory, ClassData(typeof(HandlebarsEnvGenerator))]
Expand Down
4 changes: 2 additions & 2 deletions source/Handlebars.Test/TripleStashTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void UnencodedEncodedUnencoded()
var data = new
{
a_bool = false,
dangerous_value = "<div>There's HTML here</div>"
dangerous_value = "<div>There is HTML here</div>"
};

var result = template(data);
Assert.Equal("<div>There's HTML here</div>...&lt;div&gt;There's HTML here&lt;/div&gt;...<div>There's HTML here</div>!", result);
Assert.Equal("<div>There is HTML here</div>...&lt;div&gt;There is HTML here&lt;/div&gt;...<div>There is HTML here</div>!", result);
}
}
}
Expand Down

0 comments on commit a2dd13a

Please sign in to comment.