Handlebars.Net inserts Japanese Characters and converts them to Unicode Decimal Code

36 Views Asked by At

Simple example

        public class TemplateData {
             public string inputstring = "あ";
        }
        public static string HandleBar()
        {
            var message = "{{inputstring}}";
            var handlebars = Handlebars.Create();
            // needed so if statements work properly.
            handlebars.Configuration.UseNewtonsoftJson();
            var template = handlebars.Compile(message);
            var result = template(new TemplateData);

            return result;
        }

output will not be it is instead, あ

How do I fix this?

1

There are 1 best solutions below

0
Worthy7 On

It seems Handlebars will escape some characters, so I added unescape code and it worked correctly.


        public class TemplateData {
             public string inputstring = "あ";
        }
        public static string HandleBar()
        {
            var message = "{{inputstring}}";
            var handlebars = Handlebars.Create();
            // needed so if statements work properly.
            handlebars.Configuration.UseNewtonsoftJson();
            var template = handlebars.Compile(message);
            var result = template(new TemplateData);

            result = System.Net.WebUtility.HtmlDecode(result);
            return result;
        }