Skip to content
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

Add back IHtmlString to System.Web.HttpUtility #85673

Merged
merged 2 commits into from
May 3, 2023

Conversation

stephentoub
Copy link
Member

Fixes #83477

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned stephentoub May 2, 2023
@ghost
Copy link

ghost commented May 2, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #83477

Author: stephentoub
Assignees: -
Labels:

area-System.Net, new-api-needs-documentation

Milestone: -

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

value switch
{
null => null,
IHtmlString ihs => ihs.ToHtmlString() ?? string.Empty,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the Framework implementation doesn't alter null to string.Empty.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth on it... part of the problem is since .NET Framework we've annotated the method as returning non-null.

Also, even for the non-IHtmlString case, Framework allows null to be returned and core doesn't, right? I'd need to double check but I believe that's what I saw. In which case this is just staying consistent with what the API is doing for other inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, even for the non-IHtmlString case, Framework allows null to be returned and core doesn't, right?

Yes - a class that returns a null value from .ToString() returns a null value on framework, but a string.Empty on core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - should IHtmlstring.ToHtmlString() be nullable since we're checking it here?

Copy link
Member Author

@stephentoub stephentoub May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You tell me :-) My assumption was we don't expect null to be valid; the check is just in case. But if null is valid, then yes, this should be nullable. In all the implementations you've seen, is null expected?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I'm out sick and slow responding :) I found a number of implementations in the wild and there are no checks to validate if it is null or not, and the equivalent type on ASP.NET Core accepts a nullable string. Seems like it should be nullable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here, though, as the type itself is the important thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it in #85742.

value switch
{
null => null,
IHtmlString ihs => ihs.ToHtmlString() ?? string.Empty,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, even for the non-IHtmlString case, Framework allows null to be returned and core doesn't, right?

Yes - a class that returns a null value from .ToString() returns a null value on framework, but a string.Empty on core.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we already do ?? string.Empty for ToString(), doing the same for ToHtmlString() makes sense to me even if it's not annotated to be nullable. I tried searching for ": IHtmlString" in grep.app, but quickly realized that I can't rightly determine if any of those implementations can return null without nullable annotations. I assume it's rare though.

@stephentoub stephentoub merged commit 29d8a16 into dotnet:main May 3, 2023
@stephentoub stephentoub deleted the ihtmlstring branch May 3, 2023 20:51
@karelz karelz added this to the 8.0.0 milestone May 27, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add System.Web.IHtmlString and System.Web.HtmlString to System.Web.HttpUtility
6 participants