Skip to content

x/net/html: html entity escape error #48237

Closed
@aionbit

Description

@aionbit

What version of Go are you using (go version)?

$ go version
go version go1.14.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/fnwcoder/Code/go-filter-ad2/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hh/kr4769hj0tb4kjckqhlbhgww0000gn/T/go-build221547048=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"fmt"
	"golang.org/x/net/html"
	"strings"
	"log"
	"os"
)

func main() {
	root, err := html.Parse(strings.NewReader("<body><!--<p></p>&lt;!--[video]--&gt;--></body>"))
	if err != nil {
		log.Fatal(err)
	}

	c := findCommentNode(root)
	fmt.Printf("Comment Node Type: %d; Data: %q\n\n", c.Type, c.Data)

	fmt.Println("html.Render:")
	if err := html.Render(os.Stdout, c); err != nil {
		log.Fatal(err)
	}
	fmt.Println()
}

func findCommentNode(n *html.Node) *html.Node {
	if n.Type == html.CommentNode {
		return n
	}
	for n := n.FirstChild; n != nil; n = n.NextSibling {
		if nn := findCommentNode(n); nn != nil {
			return nn
		}
	}
	return nil
}

What did you expect to see?

Comment Node Type: 4; Data: "<p></p><!--[video]-->"

html.Render:
<!--<p></p>&lt;!--[video]--&gt;-->

What did you see instead?

Comment Node Type: 4; Data: "<p></p><!--[video]-->"

html.Render:
<!--<p></p><!--[video]-->-->

refer:PuerkitoBio/goquery#391

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions