I'm trying to come up with a test suite which checks HTML fragments/files are canonically equivalent to one another. I was surprised to see that if I parse the same string or file, the https://godoc.org/golang.org/x/net/html#Node was comparing as different. What am I missing?
Hopefully this demonstrates the issue:
package main
import (
"fmt"
"strings"
"golang.org/x/net/html"
)
func main() {
s := `<h1>
test
</h1><p>foo</p>`
// s2 := `<h1>test</h1><p>foo</p>`
doc, _ := html.Parse(strings.NewReader(s))
doc2, _ := html.Parse(strings.NewReader(s))
if doc == doc2 {
fmt.Println("HTML is the same") // Expected this
} else {
fmt.Println("HTML is not the same") // Got this
}
}
HTML is not the same