You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"golang.org/x/net/html"
"strings"
)
func parseAndPrint(s string) {
root, _ := html.Parse(strings.NewReader(s))
var out strings.Builder
html.Render(&out, root)
fmt.Printf("%q", out.String())
}
func main() {
// Only this one produces unexpected output.
parseAndPrint("<pre> crlf</pre>")
fmt.Println()
// All these remaining lines are to show that only the first newline, either CR or LF is stripped.
parseAndPrint("<pre> lfcr</pre>")
fmt.Println()
parseAndPrint("<pre> crcr</pre>")
fmt.Println()
parseAndPrint("<pre> lflf</pre>")
fmt.Println()
}
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.11rc2 linux/amd64
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
What did you do?
https://play.golang.org/p/_79yZsnUz4j
What did you expect to see?
The spec says that a leading newline character immediately following the
<pre>
element start tag is stripped. https://html.spec.whatwg.org/#the-pre-elementDon't even get me started on how this makes parse and print non-idempotent.
But I would expect only the FIRST newline to be stripped.
What did you see instead?
This bit of code strips the exact sequence of CR followed immediately by LF, so it's effectively stripping two instead of one.
Happy to submit a patch. I think the correct logic should be:
The text was updated successfully, but these errors were encountered: