Skip to content

encoding/xml: Parsing of CDATA yields incorrect error. #1112

@gopherbot

Description

@gopherbot

by jimteeuwen:

What steps will reproduce the problem?
Build and run the following code:

package main

import "xml"
import "strings"
import "fmt"
import "os"

func main() {
    fragment := `<test><![CDATA[ &val=foo ]]></test>`
    parser := xml.NewParser(strings.NewReader(fragment))
    
    var err os.Error

    for {
        if _, err = parser.Token(); err != nil {
            if err == os.EOF {
                return
            }
            fmt.Fprintf(os.Stderr, "Xml Error: %s\n", err)
            return
        }
    }
}

What is the expected output?
Program should run without error.

What do you see instead?
Xml Error: XML syntax error on line 1: invalid character entity &val;

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
64-bit ArchLinux

Which revision are you using?  (hg identify)
e1752be5d932 tip

Please provide any additional information below.
The XML parser in the Go xml package should ignore special tokens like & and < or
> when they are inside a <![CDATA[ ... ]]> tag.
The current implementation does not and consequently yields parse errors where it should
not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions