Skip to content

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

@AnorZaken

Description

@AnorZaken

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions