golang/go

encoding/xml: add whitespace normalization from spec

Open

#20,614 opened on Jun 8, 2017

View on GitHub
 (13 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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?

for attribute values, all whitespace characters (#x20, #xD, #xA, #x9), should be normalized to a space character (see https://www.w3.org/TR/REC-xml/#AVNormalize)

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

package main

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

func main() {
	decoder := xml.NewDecoder(strings.NewReader(`<a p1="v1

v1"/>`))
	t, _ := decoder.Token()
	if e, ok := t.(xml.StartElement); ok {
		fmt.Printf("%q", e.Attr[0].Value)
	}
}

What did you expect to see?

"v1  v1"

What did you see instead?

"v1\n\nv1"

Tested the same with xmllint program:

$ cat test.xml
<x p1="v1

v2"/>
$ xmllint test.xml
<?xml version="1.0"?>
<x p1="v1  v2"/>

Contributor guide