mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
xml: allow unquoted attribute values in non-Strict mode
HTML4 standard supports unquoted attibute values in certain cases (http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2). R=rsc CC=golang-dev https://golang.org/cl/207095
This commit is contained in:
parent
00d29db3a9
commit
d8675d25e5
2 changed files with 55 additions and 8 deletions
|
|
@ -589,14 +589,7 @@ func (p *Parser) RawToken() (Token, os.Error) {
|
|||
return nil, p.err
|
||||
}
|
||||
p.space()
|
||||
if b, ok = p.mustgetc(); !ok {
|
||||
return nil, p.err
|
||||
}
|
||||
if b != '"' && b != '\'' {
|
||||
p.err = SyntaxError("unquoted or missing attribute value in element")
|
||||
return nil, p.err
|
||||
}
|
||||
data := p.text(int(b), false)
|
||||
data := p.attrval()
|
||||
if data == nil {
|
||||
return nil, p.err
|
||||
}
|
||||
|
|
@ -610,6 +603,40 @@ func (p *Parser) RawToken() (Token, os.Error) {
|
|||
return StartElement{name, attr}, nil
|
||||
}
|
||||
|
||||
func (p *Parser) attrval() []byte {
|
||||
b, ok := p.mustgetc()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
// Handle quoted attribute values
|
||||
if b == '"' || b == '\'' {
|
||||
return p.text(int(b), false)
|
||||
}
|
||||
// Handle unquoted attribute values for strict parsers
|
||||
if p.Strict {
|
||||
p.err = SyntaxError("unquoted or missing attribute value in element")
|
||||
return nil
|
||||
}
|
||||
// Handle unquoted attribute values for unstrict parsers
|
||||
p.ungetc(b)
|
||||
p.buf.Reset()
|
||||
for {
|
||||
b, ok = p.mustgetc()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
// http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2
|
||||
if 'a' <= b && b <= 'z' || 'A' <= b && b <= 'Z' ||
|
||||
'0' <= b && b <= '9' || b == '_' || b == ':' || b == '-' {
|
||||
p.buf.WriteByte(b)
|
||||
} else {
|
||||
p.ungetc(b)
|
||||
break
|
||||
}
|
||||
}
|
||||
return p.buf.Bytes()
|
||||
}
|
||||
|
||||
// Skip spaces if any
|
||||
func (p *Parser) space() {
|
||||
for {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue