Skip to content

Commit

Permalink
Add readme section.
Browse files Browse the repository at this point in the history
Run BasicIntegrationTests with new version of HtmlEncoder.
  • Loading branch information
tommysor committed Dec 22, 2021
1 parent cc80d19 commit 2fee90c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,43 @@ public void HelperWithDotSeparatedName()
}
```

#### HtmlEncoder
Used to switch between the legacy Handlebars.Net and the canonical Handlebars rules (or a custom implementation).\
For Handlebars.Net 2.x.x `HtmlEncoderLegacy` is the default.

`HtmlEncoder`\
Implements the canonical Handlebars rules.

`HtmlEncoderLegacy`\
Will not encode:\
= (equals)\
` (backtick)\
' (single quote)

Will encode non-ascii characters `â`, `ß`, ...\
Into HTML entities (`<`, `â`, `ß`, ...).

##### Areas
- `Runtime`

##### Example
```c#
[Fact]
public void UseCanonicalHtmlEncodingRules()
{
var handlebars = Handlebars.Create();
handlebars.Configuration.TextEncoder = new HtmlEncoder();

var source = "{{Text}}";
var value = new { Text = "< â" };

var template = handlebars.Compile(source);
var actual = template(value);

Assert.Equal("&lt; â", actual);
}
```

## Performance

### Compilation
Expand Down
1 change: 1 addition & 0 deletions source/Handlebars.Test/BasicIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class HandlebarsEnvGenerator : IEnumerable<object[]>
types.Add(typeof(Dictionary<long, object>));
types.Add(typeof(Dictionary<string, string>));
})),
Handlebars.Create(new HandlebarsConfiguration().Configure(o => o.TextEncoder = new HtmlEncoder())),
};

public IEnumerator<object[]> GetEnumerator() => _data.Select(o => new object[] { o }).GetEnumerator();
Expand Down

0 comments on commit 2fee90c

Please sign in to comment.