TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
210 stars 53 forks source link

Property names with special characters (ä,ö,ü) are converted to unicode strings #30

Closed skriebi closed 2 years ago

skriebi commented 6 years ago

Hello,

some of the columns in our database contains special characters (ä,ö,ü). The characters are converted to ä, ö or ü unicode strings.

To solve the issue for me, I have created a hbs-helper, which simple writes the property-name with the WriteSafeString-Method of the TextWriter.

Helper registration:

    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
        var options = ReverseEngineerOptions.DbContextAndEntities;
        services.AddHandlebarsScaffolding(options);

        Handlebars.RegisterHelper("f-pn", FormatPropertyName);
    }

    void FormatPropertyName(TextWriter writer, object context, object[] args)
    {
        writer.WriteSafeString(args[0].ToString());
    }

Usage in templates: {{f-pn property-name}}

I think, the property-name template should use the WriteSafeString-Method.

tonysneed commented 6 years ago

You should add your helper like so:

services.AddHandlebarsHelpers(myHelper);

See here.

I think, the property-name template should use the WriteSafeString-Method.

Perhaps you should open an issue on Handlebars.Net, since the templates should use WriteSafeString? I recommend that, because it would solve the problem of special characters globally.

ErikEJ commented 6 years ago

Reported here: https://github.com/ErikEJ/EFCorePowerTools/issues/77

ErikEJ commented 6 years ago

EF Core team (and I) use UTF8 encoding...

tonysneed commented 5 years ago

@ErikEJ What do you think I should do to fix this?

ErikEJ commented 5 years ago

It looks like a Handlebars issue to me... https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars/blob/master/src/EntityFrameworkCore.Scaffolding.Handlebars/Internal/FileSystemFileService.cs#L65

tonysneed commented 5 years ago

Confirmed this is a Handlebars.Net issue. There needs to be a way to suppress HTML encoding. See Issue 276 there.

tonysneed commented 5 years ago

Closing, as this needs to be fixed by Handlebars.NET.

tonysneed commented 3 years ago

Re-opening, as this issue was fixed in v2 of Handlebars.Net.

Varorbc commented 2 years ago

If this option is not checked, Chinese will not be encoded.

image

ErikEJ commented 2 years ago

The option is: Use Data Annotations

Varorbc commented 2 years ago

In addition, it is strange that some Chinese is not encoded

Varorbc commented 2 years ago

In my investigation, I found that some Chinese are not encoded because SuppressEncoding is true, because I am not familiar with this project and do not know where to assign SuppressEncoding

https://github.com/Handlebars-Net/Handlebars.Net/blob/ad5c616c58397c6d52507c859cb9f1b397580e3a/source/Handlebars/IO/EncodedTextWriter.cs#L48-L57

tonysneed commented 2 years ago

This flag was added in Handlebars.Net in v 2 and defaults to true. I think we just need to set it to false.

tonysneed commented 2 years ago

I am wondering how to reproduce the encoding issue on my side. @Varorbc, @ErikEJ Any tips?

Varorbc commented 2 years ago

Not so.This flag already exists in Handlebar. Net in V1.I think we should find out why some Chinese SuppressEncoding is false and some Chinese SuppressEncoding is true instead of directly modifying the default value

tonysneed commented 2 years ago

@Varorbc I think the setting is NoEscape. According to issue 276 in Handlebars.Net, support for noEscape was added to Handlebars.Net with PR 375 in 2.0.0-preview-2. I will look into how we can set this to true.

tonysneed commented 2 years ago

@Varorbc Please pull down PR #178 and test to see if it resolves encoding issues.