• Russ Cox's avatar
    [release-branch.go1.8] encoding/xml: disable checking of attribute syntax, like Go 1.7 · 02240408
    Russ Cox authored
    Consider this struct, which expects an attribute A and a child C both ints:
    
        type X struct {
            XMLName xml.Name `xml:"X"`
            A       int      `xml:",attr"`
            C       int
        }
    
    Go 1.2 through Go 1.7 were consistent: attributes unchecked,
    children strictly checked:
    
        $ go1.7 run /tmp/x.go
        <X></X>              ok
        <X A=""></X>         ok
        <X A="bad"></X>      ok
        <X></X>              ok
        <X><C></C></X>       ERROR strconv.ParseInt: parsing "": invalid syntax
        <X><C/></X>          ERROR strconv.ParseInt: parsing "": invalid syntax
        <X><C>bad</C></X>    ERROR strconv.ParseInt: parsing "bad": invalid syntax
        $
    
    Go 1.8 made attributes strictly checked, matching children:
    
        $ go1.8 run /tmp/x.go
        <X></X>              ok
        <X A=""></X>         ERROR strconv.ParseInt: parsing "": invalid syntax
        <X A="bad"></X>      ERROR strconv.ParseInt: parsing "bad": invalid syntax
    ...
    02240408
xml_test.go 20.9 KB