ltrzesniewski / RazorBlade

Compile Razor templates at build-time without a dependency on ASP.NET.
MIT License
149 stars 7 forks source link

Improve HTML encode to handle single quotes #9

Closed slang25 closed 1 year ago

slang25 commented 1 year ago

This library is great! I found that it doesn't HTML escape single quotes, so here's a small PR...

ltrzesniewski commented 1 year ago

Thanks! I thought single quotes didn't really need to be escaped. Did you find a case where it's an issue?

slang25 commented 1 year ago

So I coded this up late last night, hence the mistakes 😄 What led me to create this PR is that my test started failing after switching from RazorLight, it is expecting ' for '. From some research, it should be encoded to either ' or ' (this is the hex representation), however I chose the hex implementation as it's what the other razor libraries do, and that's what the System.Text.Encodings.Web.HtmlEncoder.Default implementation does:

System.Text.Encodings.Web.HtmlEncoder.Default.Encode("foo's").ShouldBe("foo's");

So copying this would lead to less surprises for future adopters.

ltrzesniewski commented 1 year ago

Ok, thanks for the explanation. I'll review this in more detail tonight, but I can already say that:

slang25 commented 1 year ago

Thanks for catching those @ltrzesniewski, changes made

slang25 commented 1 year ago

I'm thinking this should also handle chars outside of the ASCII range, let me take a quick look at that too

ltrzesniewski commented 1 year ago

I don't think that's really required, everything handles Unicode now.

ltrzesniewski commented 1 year ago

I released this in v0.4.3 - thanks! 🙂

slang25 commented 1 year ago

Amazing, thanks @ltrzesniewski