diff --git a/source/Handlebars.Test/Issues/Issue543Tests.cs b/source/Handlebars.Test/Issues/Issue543Tests.cs
new file mode 100644
index 00000000..6c1ae250
--- /dev/null
+++ b/source/Handlebars.Test/Issues/Issue543Tests.cs
@@ -0,0 +1,26 @@
+using Xunit;
+
+namespace HandlebarsDotNet.Test
+{
+ public class Issue543Tests
+ {
+ [Fact]
+ public void Subexpression_WriteSafeString_NotDoubleEncoded()
+ {
+ var h = Handlebars.Create();
+ h.RegisterHelper("func2", (writer, ctx, args) => writer.WriteSafeString("bold"));
+ h.RegisterHelper("func1", (writer, ctx, args) => writer.WriteSafeString($"{args[0]}"));
+ var result = h.Compile("{{func1 (func2)}}")(new { });
+ Assert.Equal("bold", result);
+ }
+
+ [Fact]
+ public void Standalone_WriteSafeString_NotEncoded()
+ {
+ var h = Handlebars.Create();
+ h.RegisterHelper("func2", (writer, ctx, args) => writer.WriteSafeString("bold"));
+ var result = h.Compile("{{func2}}")(new { });
+ Assert.Equal("bold", result);
+ }
+ }
+}
diff --git a/source/Handlebars/Compiler/Translation/Expression/PartialBinder.cs b/source/Handlebars/Compiler/Translation/Expression/PartialBinder.cs
index 57467832..354be2ad 100644
--- a/source/Handlebars/Compiler/Translation/Expression/PartialBinder.cs
+++ b/source/Handlebars/Compiler/Translation/Expression/PartialBinder.cs
@@ -12,6 +12,12 @@ internal class PartialBinder : HandlebarsExpressionVisitor
{
private static string SpecialPartialBlockName = "@partial-block";
+ private static string ToPartialName(object value)
+ {
+ if (value is SafeString safe) return safe.Value;
+ return (string) value;
+ }
+
private CompilationContext CompilationContext { get; }
public PartialBinder(CompilationContext compilationContext)
@@ -46,7 +52,8 @@ protected override Expression VisitPartialExpression(PartialExpression pex)
bindingContext = bindingContext.Call(o => o.CreateChildContext(value, partialTemplate));
}
- var partialName = Cast(pex.PartialName);
+ var partialNameObj = Arg