xml: Fixed CDATA parsing.

Fixes #128.

R=r, rsc
https://golang.org/cl/154126
This commit is contained in:
Abhinav Gupta 2009-11-14 11:46:09 -08:00 committed by Russ Cox
parent 14a4ece979
commit bad9738be6
2 changed files with 9 additions and 5 deletions

View File

@ -497,11 +497,11 @@ func (p *Parser) RawToken() (Token, os.Error) {
case '[': // <![ case '[': // <![
// Probably <![CDATA[. // Probably <![CDATA[.
for i := 0; i < 7; i++ { for i := 0; i < 6; i++ {
if b, ok = p.getc(); !ok { if b, ok = p.getc(); !ok {
return nil, p.err return nil, p.err
} }
if b != "[CDATA["[i] { if b != "CDATA["[i] {
p.err = SyntaxError("invalid <![ sequence"); p.err = SyntaxError("invalid <![ sequence");
return nil, p.err; return nil, p.err;
} }

View File

@ -24,7 +24,7 @@ const testInput = `
<inner/> <inner/>
</outer> </outer>
<tag:name> <tag:name>
Some text here. <![CDATA[Some text here.]]>
</tag:name> </tag:name>
</body><!-- missing final newline -->` </body><!-- missing final newline -->`
@ -52,7 +52,9 @@ var rawTokens = []Token{
EndElement{Name{"", "outer"}}, EndElement{Name{"", "outer"}},
CharData(strings.Bytes("\n ")), CharData(strings.Bytes("\n ")),
StartElement{Name{"tag", "name"}, nil}, StartElement{Name{"tag", "name"}, nil},
CharData(strings.Bytes("\n Some text here.\n ")), CharData(strings.Bytes("\n ")),
CharData(strings.Bytes("Some text here.")),
CharData(strings.Bytes("\n ")),
EndElement{Name{"tag", "name"}}, EndElement{Name{"tag", "name"}},
CharData(strings.Bytes("\n")), CharData(strings.Bytes("\n")),
EndElement{Name{"", "body"}}, EndElement{Name{"", "body"}},
@ -83,7 +85,9 @@ var cookedTokens = []Token{
EndElement{Name{"ns2", "outer"}}, EndElement{Name{"ns2", "outer"}},
CharData(strings.Bytes("\n ")), CharData(strings.Bytes("\n ")),
StartElement{Name{"ns3", "name"}, nil}, StartElement{Name{"ns3", "name"}, nil},
CharData(strings.Bytes("\n Some text here.\n ")), CharData(strings.Bytes("\n ")),
CharData(strings.Bytes("Some text here.")),
CharData(strings.Bytes("\n ")),
EndElement{Name{"ns3", "name"}}, EndElement{Name{"ns3", "name"}},
CharData(strings.Bytes("\n")), CharData(strings.Bytes("\n")),
EndElement{Name{"ns2", "body"}}, EndElement{Name{"ns2", "body"}},