encoding/xml: parse comments in DOCTYPE

R=rsc, n13m3y3r
CC=golang-dev
https://golang.org/cl/6330061
This commit is contained in:
Shawn Smith 2012-08-31 18:09:31 -04:00 committed by Russ Cox
parent 2785f9528e
commit a11b748fa2
2 changed files with 63 additions and 1 deletions

View file

@ -584,6 +584,7 @@ func (d *Decoder) RawToken() (Token, error) {
if inquote == 0 && b == '>' && depth == 0 {
break
}
HandleB:
d.buf.WriteByte(b)
switch {
case b == inquote:
@ -599,7 +600,35 @@ func (d *Decoder) RawToken() (Token, error) {
depth--
case b == '<' && inquote == 0:
depth++
// Look for <!-- to begin comment.
s := "!--"
for i := 0; i < len(s); i++ {
if b, ok = d.mustgetc(); !ok {
return nil, d.err
}
if b != s[i] {
for j := 0; j < i; j++ {
d.buf.WriteByte(s[j])
}
depth++
goto HandleB
}
}
// Remove < that was written above.
d.buf.Truncate(d.buf.Len() - 1)
// Look for terminator.
var b0, b1 byte
for {
if b, ok = d.mustgetc(); !ok {
return nil, d.err
}
if b0 == '-' && b1 == '-' && b == '>' {
break
}
b0, b1 = b1, b
}
}
}
return Directive(d.buf.Bytes()), nil