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: StartElement and EndElement should not match if prefix does not match #20685

Open
santhosh-tekuri opened this issue Jun 15, 2017 · 8 comments

Comments

@santhosh-tekuri
Copy link
Contributor

commented Jun 15, 2017

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

go version go1.8.3 darwin/amd64

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

darwin/amd64

What did you do?

StartElement and EndElement should not match if prefix does not match

go program used to test: (https://play.golang.org/p/3hUyUhbK5D)

package main

import (
	"encoding/xml"
	"fmt"
	"io"
	"strings"
)

func main() {
	data := `<x:book xmlns:x="abcd" xmlns:y="abcd">one</y:book>`
	decoder := xml.NewDecoder(strings.NewReader(data))
	for {
		_, err := decoder.Token()
		if err != nil {
			if err != io.EOF {
				fmt.Println(err)
			}
			return
		}
	}
}

What did you expect to see?

XML syntax error on line 1: element <x:book> closed by </y:book>

What did you see instead?

``

Tested the same with xmllint program:

$ cat test.xml
<x:book xmlns:x="abcd" xmlns:y="abcd">one</y:book>
$ xmllint test.xml
test.xml:1: parser error : Opening and ending tag mismatch: book line 1 and book
<x:book xmlns:x="abcd" xmlns:y="abcd">one</y:book>
                                                  ^
@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2017

Can you point to something in the XML spec that says that's invalid? It's certainly weird, but it seems possibly valid to me. x:book and y:book mean the same thing.

@santhosh-tekuri

This comment has been minimized.

Copy link
Contributor Author

commented Jun 17, 2017

from https://www.w3.org/TR/REC-xml/#sec-starttags

[Definition: The end of every element that begins with a start-tag must be marked by an end-tag containing a name that echoes the element's type as given in the start-tag:]

and name of start-tag is (https://www.w3.org/TR/REC-xml/#NT-STag)

STag	   ::=   	'<' Name (S Attribute)* S? '>'

similarly name of end-tag is (https://www.w3.org/TR/REC-xml/#NT-ETag)

ETag	   ::=   	'</' Name S? '>'

It means Name should literally match exactly in start and end tags

@santhosh-tekuri

This comment has been minimized.

Copy link
Contributor Author

commented Jun 17, 2017

element's type means from spec:

The Name in the start- and end-tags gives the element's type
@santhosh-tekuri

This comment has been minimized.

Copy link
Contributor Author

commented Jun 17, 2017

most straight forward mention (https://www.w3.org/TR/REC-xml/#sec-logical-struct)

Well-formedness constraint: Element Type Match

The Name in an element's end-tag must match the element type in the start-tag.
@santhosh-tekuri

This comment has been minimized.

Copy link
Contributor Author

commented Jun 17, 2017

you can also test with https://validator.w3.org/, to confirm

@andybons andybons added this to the Unplanned milestone Apr 11, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Apr 15, 2018

Change https://golang.org/cl/107255 mentions this issue: encoding/xml : fix closing tag failure

@iWdGo

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2018

Push/pop of elements name must be done using the eventual prefix together with the tag name.
The operation is moved before the translation of prefix into its URI.
One end element of a test is fixed as expecting the last used namespace is incorrect.
After closing a tag using a namespace, the valid namespace must be taken from the opening tag.
Several tests added in the submitted fix.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 27, 2018

Change https://golang.org/cl/109855 mentions this issue: encoding/xml : Fixes to enforce XML namespace standard

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