Skip to content

encoding/xml: allows invalid comments #11112

Closed
@dvyukov

Description

@dvyukov

The following program crashes with the panic:

package main

import (
    "encoding/xml"
)

type X struct {
    D string `xml:",comment"`
}

func main() {
    data := []byte("<X><!------></X>")
    v := new(X)
    if xml.Unmarshal(data, v) != nil {
        return
    }
    if _, err := xml.Marshal(v); err != nil {
        panic(err)
    }
}
panic: xml: comments must not contain "--"
goroutine 1 [running]:
main.main()
    xml.go:18 +0x129

The XML is malformed, as per XML spec:

http://www.w3.org/TR/REC-xml/#sec-comments
Comment ::= ''

Unmarshal must reject it.

on commit 306f8f1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions