Skip to content
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

encoding/xml: decoding XML with entities not supported #30983

kunalgrover05 opened this Issue Mar 21, 2019 · 1 comment


None yet
3 participants
Copy link

commented Mar 21, 2019

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

$ go version

Does this issue reproduce with the latest release?


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

Linux AMD64

go env Output
$ go env

What did you do?

XML entity support

	s := "<?xml version='1.0' encoding='ISO-8859-1'?><!DOCTYPE foo [ <!ENTITY test 'hello' > ]><Users><User><Name>&test;</Name></User></Users>"

	reader := strings.NewReader(s)
	decoder := xml.NewDecoder(reader)
	decoder.CharsetReader = charset.NewReaderLabel

	for {
		token, err := decoder.Token()
		if err != nil && err != io.EOF {
			fmt.Printf("Error! Decoding XML failed: %v\n", err)
		if token == nil {
		switch element := token.(type) {
		case xml.CharData:
			fmt.Printf("%s\n", element)


Error! Decoding XML failed: XML syntax error on line 1: invalid character entity &test;

Parsed data with decoder.Strict = false


What did you expect to see?

Entities and External entities to be processed as per

What did you see instead?


This comment has been minimized.

Copy link

commented Mar 22, 2019

I'm not experienced with XML, but have you had a look at #4196? And possibly #20614 too, since I see some extra whitespace in there.

@katiehockman katiehockman changed the title encoding/xml Decoding XML with entities not supported encoding/xml: decoding XML with entities not supported Mar 22, 2019

@julieqiu julieqiu added this to the Go1.13 milestone Apr 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.