dotnet / dotnet/dotnet-api-docs

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

Open
#12,454 6 comments 0 reactions 0 assignees View on GitHub
area-System.Text.Encodings.Web
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Missing information

### Description

The documentation simply specifies "Returns: [OperationStatus](https://learn.microsoft.com/en-us/dotnet/api/system.buffers.operationstatus?view=net-10.0) 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.