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

Open
kunalgrover05 opened this Issue Mar 21, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@kunalgrover05
Copy link

commented Mar 21, 2019

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

$ go version
1.9

Does this issue reproduce with the latest release?

Yes

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)
			break
		}
		if token == nil {
			break
		}
		switch element := token.(type) {
		case xml.CharData:
			fmt.Printf("%s\n", element)
		}
	}

Exception

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

Parsed data with decoder.Strict = false

&pwnd;

What did you expect to see?

Entities and External entities to be processed as per https://www.w3.org/TR/xml/#sec-entity-decl

What did you see instead?

@mvdan

This comment has been minimized.

Copy link
Member

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.