Skip to content

Commit 64bf3a8

Browse files
authored
Merge pull request #538 from Nisden/InlineBlockShouldNotGetEscaped
Rendering inline blocks are incorrectly escaped
2 parents e6e4d53 + b2a73bd commit 64bf3a8

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

source/Handlebars.Test/ViewEngine/ViewEngineTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ public void CanLoadAViewWithALayoutInTheRoot()
7373
Assert.Equal("layout start\r\nThis is the body\r\nlayout end", output);
7474
}
7575

76+
[Fact]
77+
public void CanRenderInlineBlocks()
78+
{
79+
// This sample is based on https://handlebarsjs.com/examples/partials/inline-blocks.html
80+
81+
var files = new FakeFileSystem()
82+
{
83+
//Given a layout in a subfolder
84+
{ "partials/layout.hbs", "<div class=\"nav\">\r\n{{> nav}}\r\n</div>\r\n<div class=\"content\">\r\n{{> content}}\r\n</div>"},
85+
86+
{ "template.hbs", "{{#> layout}}\r\n{{#*inline \"nav\"}}\r\n{{Text}}\r\n{{/inline}}\r\n{{#*inline \"content\"}}\r\nMy Content\r\n{{/inline}}\r\n{{/layout}}"}
87+
};
88+
89+
//When a viewengine renders that view
90+
var handleBars = Handlebars.Create(new HandlebarsConfiguration() { FileSystem = files });
91+
var renderView = handleBars.CompileView("template.hbs");
92+
var output = renderView(new Dictionary<string, string>
93+
{
94+
{ "Text", "<My Nav>" }
95+
});
96+
97+
//Then the correct output should be rendered
98+
Assert.Equal("<div class=\"nav\">\r\n&lt;My Nav&gt;\r\n</div>\r\n<div class=\"content\">\r\nMy Content\r\n</div>", output);
99+
}
100+
76101
[Fact]
77102
public void CanLoadAViewWithALayoutWithAVariable()
78103
{

source/Handlebars/FileSystemPartialTemplateResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public bool TryRegisterPartial(IHandlebars env, string partialName, string templ
2727

2828
handlebarsTemplateRegistrations.RegisteredTemplates.AddOrReplace(partialName, (writer, o, data) =>
2929
{
30-
writer.Write(compiled(o, data));
30+
((EncodedTextWriterWrapper)writer).Write(compiled(o, data), false);
3131
});
3232

3333
return true;

0 commit comments

Comments
 (0)