Documentation of HtmlEncoder.EncodeUtf8 fails to mention that OperationStatus.InvalidData is *never* returned.

Open Beginner friendly
#12,454 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
75/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
csharp
Domain
documentation

Research direction

Start in xml/System.Text.Encodings.Web/TextEncoder.xml and locate the EncodeUtf8 documentation for the linked overload. Check how its return status is described, then update the documentation to explain invalid UTF-8 substitution and that InvalidData is never returned; done means the generated API page makes these behaviors explicit.

Written by the indexing model from the issue text.

Description

area-System.Text.Encodings.Web
Type of issue

Missing information

Description

The documentation simply specifies "Returns: OperationStatus A status code that describes the result of the encoding operation."

This leads to the assumption, after one looks at the available enum values, that the method performs some form of validation, i.e. can return OperationStatus.InvalidData. This is not the case. It always substitutes invalid UTF-8 with Rune.ReplacementChar (U+FFFD) and proceeds with the encoding unperturbed, always returning success unless it runs into the other two failure options of DestinationTooSmall or NeedMoreData (the latter only if param isFinalBlock is false).

There is no mention of this either on the method nor at the class description level: https://learn.microsoft.com/en-us/dotnet/api/system.text.encodings.web.textencoder?view=net-10.0

Only way to find out is when unexpected output is encountered in production / tests or if one closely examines the source code.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.text.encodings.web.textencoder.encodeutf8?view=net-10.0#system-text-encodings-web-textencoder-encodeutf8(system-readonlyspan((system-byte))-system-span((system-byte))-system-int32@-system-int32@-system-boolean)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Text.Encodings.Web/TextEncoder.xml

Document Version Independent Id

fe83a6cc-fcae-66ff-b7a5-154fcfdb6d48

Platform Id

9ea117b6-6558-ee75-e0ca-d7451eac5e22

Article author

@dotnet-bot

Dominant language
C#
Stars
950
Forks
1.7k
Avg merge
3d 5h
Merged PRs (30d)
38

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/dotnet-api-docs

All issues in dotnet/dotnet-api-docs

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.