xml: permit nested directives

Return <!DOCTYPE ...> with nested directives as one big token.

Fixes #1549.

R=niemeyer, rsc
CC=golang-dev
https://golang.org/cl/4216050
This commit is contained in:
Chris Dollin 2011-02-28 14:09:04 -05:00 committed by Russ Cox
parent b2efedbf36
commit b00f7310f3
2 changed files with 67 additions and 2 deletions

View file

@ -541,17 +541,36 @@ func (p *Parser) RawToken() (Token, os.Error) {
}
// Probably a directive: <!DOCTYPE ...>, <!ENTITY ...>, etc.
// We don't care, but accumulate for caller.
// We don't care, but accumulate for caller. Quoted angle
// brackets do not count for nesting.
p.buf.Reset()
p.buf.WriteByte(b)
inquote := uint8(0)
depth := 0
for {
if b, ok = p.mustgetc(); !ok {
return nil, p.err
}
if b == '>' {
if inquote == 0 && b == '>' && depth == 0 {
break
}
p.buf.WriteByte(b)
switch {
case b == inquote:
inquote = 0
case inquote != 0:
// in quotes, no special action
case b == '\'' || b == '"':
inquote = b
case b == '>' && inquote == 0:
depth--
case b == '<' && inquote == 0:
depth++
}
}
return Directive(p.buf.Bytes()), nil
}