-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for IHtmlString and HtmlString #205
Comments
A couple of alternative approaches we could consider:
|
@twsouthwick I like this approach, however it does affect some fairly fundamental bits of both dotnet runtime and aspnetcore - while it would probably be the best overall solution (and possibly addresses the issue with Should I raise an issue on dotnet/runtime to add |
I've created an API proposal at dotnet/runtime#83477 to see if we can get this added to |
Progress:
|
Update:
|
Update:
All the planned changes are in, so I'll close this issue. If new issues arise, please comment or raise a new one |
Summary
Looking to add support for IHtmlString and HtmlString
Motivation and goals
I currently have some conditional compiles to target netcoreapp / net48 to use the aspnetcore IHtmlContent or IHtmlString as a result on an interface. I would prefer to have a consistent interface and not have to multitarget if possible.
In scope
Add
System.Web.IHtmlString
based onMicrosoft.AspNetCore.Html.IHtmlContent
with a default implementation ofIHtmlContent.WriteTo
Add
System.Web.HtmlString
based onMicrosoft.AspNetCore.Html.HtmlString
and implementSystem.Web.IHtmlString
Risks / unknowns
One area that could be a problem (and I think is already a 'bug' in net6) is that
System.Web.HttpUtilitity
is part of net6.The problem is that the code to detect
IHtmlString
in thepublic static string? HtmlEncode (object? value);
method is effectively missing, and it doesn't have any reference toMicrosoft.AspNetCore.Html.IHtmlContent
either. Nor is there a way to replace the implementation used. This means that if you use this method, expecting the operation where it does not encode IHtmlString, you don't get what you expect.https://github.com/dotnet/runtime/blob/04faf38fd7e8fee87b31d2698d6a566baf2ef372/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs#L145
vs
https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Web/httpserverutility.cs#L1111
Examples
This could then be used in Razor, WebForms, MVC or other ways to return a time tag for any DateTime. It would then be fine to add to an array of properties for display using HtmlEncode (except for the issue mentioned before).
Detailed design
It's often best not to fill this out until you get basic consensus about the above. When you do, consider adding an implementation proposal with the following headings:
Unfortunately, I don't see a good way of correctly implementing
HttpUtility.HtmlEncode(object?)
, other than to have it available via a different static object and/or as an extension method. Allowing changingHttpUtility.HtmlEncode(myobj)
to be replaced with eitherHttpUtility2.HtmlEncode(myobj)
ormyobj.HtmlEncode()
. Perhaps an analyser could catch this and apply code fixes?The text was updated successfully, but these errors were encountered: