Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Update HtmlEntities to decode HTML5 entities - #13152

Closed
devatwork wants to merge 1 commit into
dotnet:masterfrom
devatwork:update-html-entities-to-html5
Closed

devatwork wants to merge 1 commit into
dotnet:masterfrom
devatwork:update-html-entities-to-html5

Conversation

@devatwork

@devatwork devatwork commented Oct 29, 2016 •

Copy link
Copy Markdown

Note: I had to change the lookup from a Dictionary<string,char> to a Dictionary<string,string> in order to account for HTML entities that represent multiple Unicode characters, like &acE; for example.

Closes #13036

@karelz

Note: I had to change the lookup from a Dictionary<string,char> to a Dictionary<string,string> in order to account for HTML entities that represent multiple Unicode characters, like &acE; for example.

Closes #13036

@karelz karelz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall the change looks good. Thank you @devatwork!

Can you please add a test which will test all entities? Ideally we would read them from http://www.w3.org/TR/html5/entities.json stored as part of the test. It will nicely test completeness.

If there's an easy way to test that we do not have "extra" entities (e.g. via reflection on the private hash), that would be great.

I would also suggest to add a compat test -- grab the old hash table and make it a test case. It will ensure we didn't accidentally modify the HTML4 list in the past and that with the new table we satisfy all those entities we had prior to this change. I know, this may be a bit paranoid from my side.

BTW: Sorry for delayed response on the review ...

@devatwork

Copy link
Copy Markdown
Author

Thanks for the feedback @karelz.

I've implemented the test for the HTML4 test and it revealed an incompatibility between the HTML4 and HTML5 entity tables: the &lang; and &rang; entities are expanded differently. The change has been documented in the first bullet of https://www.w3.org/TR/2012/WD-html5-diff-20120930/#syntax-misc.

Both the dot net core and the full framework documentation do not seem to specifiy how each entity is decoded: https://msdn.microsoft.com/en-us/library/ee388354(v=vs.110).aspx and https://docs.microsoft.com/en-us/dotnet/core/api/system.net.webutility#System_Net_WebUtility_HtmlDecode_System_String_.

I would prefer to use the HTML5 entities because it is the current version of the specification but I guess there are some compatibility concerns here. Any suggestions on how to move forward with this?

Concerning the HTML5 Entities test: is it ok to take a dependency on System.Json in the test project?

@karelz

karelz commented Nov 6, 2016 •

Copy link
Copy Markdown
Member

is it ok to take a dependency on System.Json in the test project?

I think that should be fine. Tests should be able to use additional libraries. At least I don't see any reason why not.

... incompatibility between the HTML4 and HTML5 entity tables: the &lang; and &rang; entities are expanded differently. The change has been documented in the first bullet of https://www.w3.org/TR/2012/WD-html5-diff-20120930/#syntax-misc.
I would prefer to use the HTML5 entities because it is the current version of the specification but I guess there are some compatibility concerns here. Any suggestions on how to move forward with this?

I see 3 options:

  1. Support only HTML5 conversion table as it is the latest spec version as you mentioned.
  2. Support both HTML4 and HTML5 fully - that would mean either adding new API (type or arg to choose the spec version). Then we could decide what is default (likely HTML5 to move everyone to latest without requiring everyone to understand teeny-tiny details of spec versions).
  3. Support HTML5 and parts of HTML4 -- Decode would use HTML5, Encode would recognize both versions of the encoding (HTML4 and HTML5).

I am tempted to lean towards option 1. Option 2 is too complex (requires everyone fully understand the specs, while most people don't care about corner cases) and option 3 doesn't really help that much, while creating complexity and more compat burden for future.
@davidsh @CIPop @weshaggard @terrajobst @stephentoub do you have advice based on your past experience from other specs being incompatible with their previous versions?

@karelz

karelz commented Nov 9, 2016

Copy link
Copy Markdown
Member

@davidsh @CIPop @weshaggard @terrajobst @stephentoub can one of you please chime in?

@karelz

karelz commented Nov 15, 2016 •

Copy link
Copy Markdown
Member

Ping @davidsh @CIPop @weshaggard @terrajobst @stephentoub?

@devatwork if there is no reply in next day or two, let's go with option (1) above.

@devatwork

Copy link
Copy Markdown
Author

@karelz Ok, I understand this is not highest priority for the team right now. On my side I need to implement the reflection test and rebase. I think I will work on that somewhere at the end of the week.

Out of curiosity: Is there something in place to document this change in behavior (assuming we go with 1) and even provide some guidance on what consumer of the API can do to reintroduce the old behavior by changing their consuming code.

@weshaggard

Copy link
Copy Markdown
Member

I don't have a lot of context in this area but I did want to give some general guidance and pointers. I don't really like changing the behavior of this from what we have in .NET Framework as the two will be completely different after this change. I would be OK if we made the change and also brought it to .NET Framework but if we do we would need to go with option (2) with probably a quirk to opt into HTML4 behaviors. So not knowing the details I would lean towards option (2) purely to be conservative.

Lastly I wanted to point out that for legacy reasons we have two versions of this type, the one you updated System.Net.WebUtility as well as System.Web.HttpUtility. We should probably ensure some consistency between them.

@karelz

karelz commented Nov 15, 2016

Copy link
Copy Markdown
Member

@weshaggard what kind of quirk options do we have here? I would love to see options "I want to target specific HTML spec" and "I want latest HTML spec".

@weshaggard

Copy link
Copy Markdown
Member

We essentially have 2 options:

  1. We add new APIs that allow people to specify it.
  2. We use our quirking mechanism (aka AppContext.Get/SetSwitch) and introduce a quirk flag.

@CIPop

CIPop commented Nov 15, 2016

Copy link
Copy Markdown

@karelz I have no background on WebUtility or HttpUtility.
@danroth27 @Tratcher do you know who might be able to help here?

@Tratcher

Copy link
Copy Markdown
Member

@Eilon can you recommend anyone re HTML4 vs 5?

@Eilon

Eilon commented Nov 16, 2016

Copy link
Copy Markdown

@Tratcher not in particular, but perhaps @DamianEdwards has thoughts on what an API like this ought to do?

@karelz

karelz commented Nov 21, 2016

Copy link
Copy Markdown
Member

Let's move the design discussion to the issue.
I will close this PR for now, once we have design decision, we can reopen it and continue iterating on it ...

@karelz karelz closed this Nov 21, 2016
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
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.

7 participants