Skip to content

encoding/xml: add whitespace normalization from spec #20614

Open
@santhosh-tekuri

Description

@santhosh-tekuri

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"/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions