StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
399 stars 58 forks source link

Non English character problem for placeholders #145

Closed OzanGuclu closed 8 months ago

OzanGuclu commented 9 months ago

I'm currently trying to use Stubble, One of the need I have is to use Turkish "placeholders" (UTF-8 and not ASCII)

        var stubble = new StubbleBuilder().Configure(settings => settings.AddJsonNet()).Build();
        String json = "{ FullName:\"ÖMER FARUK DEMİR\"}";
        var result = JsonConvert.DeserializeObject(json);
        string Msg = stubble.Render("{{FullName}}", result);

rendered string is

image

is this a bug.

Romanx commented 8 months ago

Hi there,

I had a quick look at this. It seems to be related to the fact that by the mustache spec we HTML Encode the results of a tag. It seems theres a difference here with how dotnet and the browser encode Ö.

You can override the encoding function on the settings using settings.SetEncodingFunction() or you can set the specific tag to unescape using {{{ FullName }}} (note the tripple {) or {{ & FullName }}.

Changing our default html encoding away from the standard dotnet function feels like a bad idea due to unforseen edge cases especially when there are options to override the encoding function yourself or stop encoding for your specific case.

Hopefully this helps! 👍

OzanGuclu commented 8 months ago

thanks for the explanation.