Skip to content

Commit

Permalink
noEscape support
Browse files Browse the repository at this point in the history
  • Loading branch information
oformaniuk committed Oct 26, 2020
1 parent d0c4fef commit b12d4ff
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions source/Handlebars/Configuration/HandlebarsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public sealed class HandlebarsConfiguration : IHandlebarsTemplateRegistrations
public string UnresolvedBindingFormatter { get; set; }

public bool ThrowOnUnresolvedBindingExpression { get; set; }

public bool NoEscape { get; set; }

/// <summary>
/// The resolver used for unregistered partials. Defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public HandlebarsConfigurationAdapter(HandlebarsConfiguration configuration)
public IPartialTemplateResolver PartialTemplateResolver => UnderlingConfiguration.PartialTemplateResolver;
public IMissingPartialTemplateHandler MissingPartialTemplateHandler => UnderlingConfiguration.MissingPartialTemplateHandler;
public Compatibility Compatibility => UnderlingConfiguration.Compatibility;
public bool NoEscape => UnderlingConfiguration.NoEscape;

public IObjectDescriptorProvider ObjectDescriptorProvider { get; }
public IList<IExpressionMiddleware> ExpressionMiddleware { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,7 @@ public interface ICompiledHandlebarsConfiguration : IHandlebarsTemplateRegistrat

/// <inheritdoc cref="IPathInfoStore"/>
IPathInfoStore PathInfoStore { get; }

bool NoEscape { get; }
}
}
4 changes: 2 additions & 2 deletions source/Handlebars/HandlebarsEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private HandlebarsTemplate<TextWriter, object, object> CompileViewInternal(strin

return (writer, context, data) =>
{
using var encodedTextWriter = new EncodedTextWriter(writer, configuration.TextEncoder);
using var encodedTextWriter = new EncodedTextWriter(writer, configuration.TextEncoder, configuration.NoEscape);
if (context is BindingContext bindingContext)
{
compiledView(encodedTextWriter, bindingContext);
Expand Down Expand Up @@ -109,7 +109,7 @@ public HandlebarsTemplate<TextWriter, object, object> Compile(TextReader templat
}
else
{
using var encodedTextWriter = new EncodedTextWriter(writer, configuration.TextEncoder);
using var encodedTextWriter = new EncodedTextWriter(writer, configuration.TextEncoder, configuration.NoEscape);
if (context is BindingContext bindingContext)
{
compiledTemplate(encodedTextWriter, bindingContext);
Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/Helpers/HelperDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected HelperDescriptor(PathInfo name) : base(name)
internal sealed override object ReturnInvoke(BindingContext bindingContext, object context, in Arguments arguments)
{
using var writer = ReusableStringWriter.Get(bindingContext.Configuration.FormatProvider);
using var encodedTextWriter = new EncodedTextWriter(writer, bindingContext.Configuration.TextEncoder);
using var encodedTextWriter = new EncodedTextWriter(writer, bindingContext.Configuration.TextEncoder, bindingContext.Configuration.NoEscape);
WriteInvoke(bindingContext, encodedTextWriter, context, arguments);
return writer.ToString();
}
Expand Down

0 comments on commit b12d4ff

Please sign in to comment.