mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
xml: handle unexpected EOF while parsing and fix a bug in name
mustgetc reports unexpected EOF as SyntaxError. using mustgetc seems to be a better approach than letting the caller handle unexpected EOF every time. name: the second if statement should explicitly return ok==false. R=rsc https://golang.org/cl/174083
This commit is contained in:
parent
19c18358ca
commit
dec5bb7882
2 changed files with 104 additions and 27 deletions
|
|
@ -94,6 +94,57 @@ var cookedTokens = []Token{
|
|||
Comment(strings.Bytes(" missing final newline ")),
|
||||
}
|
||||
|
||||
var xmlInput = []string{
|
||||
// unexpected EOF cases
|
||||
"<",
|
||||
"<t",
|
||||
"<t ",
|
||||
"<t/",
|
||||
"<t/>c",
|
||||
"<!",
|
||||
"<!-",
|
||||
"<!--",
|
||||
"<!--c-",
|
||||
"<!--c--",
|
||||
"<!d",
|
||||
"<t></",
|
||||
"<t></t",
|
||||
"<?",
|
||||
"<?p",
|
||||
"<t a",
|
||||
"<t a=",
|
||||
"<t a='",
|
||||
"<t a=''",
|
||||
"<t/><![",
|
||||
"<t/><![C",
|
||||
"<t/><![CDATA[d",
|
||||
"<t/><![CDATA[d]",
|
||||
"<t/><![CDATA[d]]",
|
||||
|
||||
// other Syntax errors
|
||||
" ",
|
||||
">",
|
||||
"<>",
|
||||
"<t/a",
|
||||
"<0 />",
|
||||
"<?0 >",
|
||||
// "<!0 >", // let the Token() caller handle
|
||||
"</0>",
|
||||
"<t 0=''>",
|
||||
"<t a='&'>",
|
||||
"<t a='<'>",
|
||||
"<t> c;</t>",
|
||||
"<t a>",
|
||||
"<t a=>",
|
||||
"<t a=v>",
|
||||
// "<![CDATA[d]]>", // let the Token() caller handle
|
||||
"cdata",
|
||||
"<t></e>",
|
||||
"<t></>",
|
||||
"<t></t!",
|
||||
"<t>cdata]]></t>",
|
||||
}
|
||||
|
||||
type stringReader struct {
|
||||
s string;
|
||||
off int;
|
||||
|
|
@ -149,3 +200,15 @@ func TestToken(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyntax(t *testing.T) {
|
||||
for i := range xmlInput {
|
||||
p := NewParser(StringReader(xmlInput[i]));
|
||||
var err os.Error;
|
||||
for _, err = p.Token(); err == nil; _, err = p.Token() {
|
||||
}
|
||||
if _, ok := err.(SyntaxError); !ok {
|
||||
t.Fatalf(`xmlInput "%s": expected SyntaxError not received`, xmlInput[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue