mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
b2efedbf36
commit
b00f7310f3
2 changed files with 67 additions and 2 deletions
|
|
@ -185,6 +185,52 @@ func TestRawToken(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure that directives (specifically !DOCTYPE) include the complete
|
||||
// text of any nested directives, noting that < and > do not change
|
||||
// nesting depth if they are in single or double quotes.
|
||||
|
||||
var nestedDirectivesInput = `
|
||||
<!DOCTYPE [<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]>
|
||||
<!DOCTYPE [<!ENTITY xlt ">">]>
|
||||
<!DOCTYPE [<!ENTITY xlt "<">]>
|
||||
<!DOCTYPE [<!ENTITY xlt '>'>]>
|
||||
<!DOCTYPE [<!ENTITY xlt '<'>]>
|
||||
<!DOCTYPE [<!ENTITY xlt '">'>]>
|
||||
<!DOCTYPE [<!ENTITY xlt "'<">]>
|
||||
`
|
||||
|
||||
var nestedDirectivesTokens = []Token{
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt ">">]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt "<">]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt '>'>]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt '<'>]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt '">'>]`)),
|
||||
CharData([]byte("\n")),
|
||||
Directive([]byte(`DOCTYPE [<!ENTITY xlt "'<">]`)),
|
||||
CharData([]byte("\n")),
|
||||
}
|
||||
|
||||
func TestNestedDirectives(t *testing.T) {
|
||||
p := NewParser(StringReader(nestedDirectivesInput))
|
||||
|
||||
for i, want := range nestedDirectivesTokens {
|
||||
have, err := p.Token()
|
||||
if err != nil {
|
||||
t.Fatalf("token %d: unexpected error: %s", i, err)
|
||||
}
|
||||
if !reflect.DeepEqual(have, want) {
|
||||
t.Errorf("token %d = %#v want %#v", i, have, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestToken(t *testing.T) {
|
||||
p := NewParser(StringReader(testInput))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue