-
Notifications
You must be signed in to change notification settings - Fork 2.1k
IViewLocalizer not encoding HTML special characters #8225
Comments
That's intentional. See the docs - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#make-the-apps-content-localizable - if you want specific items to be encoded, you can use a formatted string and pass them to the localizer as a format argument. |
Thanks for the information. I didn't expect that the encoding behaviors of the localizers are different from those for Is it possible to have a localizer that encodes all returned values without using format argument? |
Changed the issue title as this issue affects |
Found a workaround (or the solution): Instead of using the item property, use the That is to change <p>@Localizer["TestContent"]</p> to <p>@Localizer.GetString("TestContent")</p> @pranavkm Do you think that the |
Sure. If it unblocks your scenario, might be worth adding it to the docs. I'd possibly mention the risk of double encoding if the original value happened to be already encoded. |
Thanks folks. Closing this as there is no action pending here. |
Using ASP.NET Core 2.1.302,
When a value in a resource file contains special characters (<, >, &, " and ') and is used in a Razor page through an
IViewLocalizer
, it is printed to the HTML output directly without any encoding. However, when it is wrapped byHtml.Encode
, the value is double encoded.Steps to reproduce:
data
:IViewLocalizer
injectedp
element in the HTML source is encoded.The text was updated successfully, but these errors were encountered: