-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/net/html: add Escape/Unescape transformers #22585
Comments
/cc @nigeltao |
Sounds reasonable to me. Sorry for the late reply. I also don't have much spare time to work on this myself. |
Sounds reasonable. |
Not at the moment, but something along the lines of (all x/text) width.Transformer or cases.Caser makes sense. Using the encoding.Encoding approach seems overkill, but may be worth it if you have a variety of matching (un)escapers. The trickiness is in the implementation. NewTransformer(FromFunc) in https://godoc.org/github.com/mpvl/textutil could help get you started. It has an example escaping and unescaping implementation. Not as efficient as implementing from scratch, but not too bad either and definitely handy for prototyping. |
Sounds good; I've actually started implementing this in the past but had trouble convincing the tests to pass, so if I give it another shot maybe I'll start with that. For me the speed wasn't as important as not buffering (very-) large documents into memory. I've done some much simpler escaping and unescaping in my XMPP address package, and that was quite a pain to get right from the ground up, so hopefully this helps. |
The
golang.org/x/net/html
package contains two functions similar to the ones in thehtml
package for escaping and unescaping HTML entities: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
(andSpanningTransformer
) interface fromgolang.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:
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
The text was updated successfully, but these errors were encountered: