Skip to content

x/net/html: add Escape/Unescape transformers #22585

Description

@SamWhited

The golang.org/x/net/html package contains two functions similar to the ones in the html package for escaping and unescaping HTML entities:

func EscapeString(string) string
func UnescapeString(string) string

unfortunately these require loading entire documents into memory and converting them to a string before attempting to escape them.

It would be nice if there were also an implementation of the Transformer (and SpanningTransformer) interface from golang.org/x/text/transform that could perform escaping / unescaping on long byte streams without requiring buffering the entire stream into memory.

This could either be two functions which return transformers:

// Escaper returns a transformer that escapes special characters.
// See EscapeString for more information.
func Escaper() transform.SpanningTransformer

// Unescaper returns a transformer that unescapes special characters.
// See UnescapeString for more information.
func Unescaper() transform.SpanningTransformer

or a Transformer type which contains all the various helper methods (String, Bytes, etc.) that transformer based packages in the text tree have.

/cc @mpvl

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions