From 16d1981a3e7ca222fb337092cc7d1cb54675268d Mon Sep 17 00:00:00 2001 From: Arvindh Rajesh Tamilmani Date: Mon, 14 Dec 2009 19:28:36 -0800 Subject: 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 http://codereview.appspot.com/174083 Committer: Russ Cox --- src/pkg/xml/xml_test.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/pkg/xml/xml_test.go') diff --git a/src/pkg/xml/xml_test.go b/src/pkg/xml/xml_test.go index 837385b6b..e689949af 100644 --- a/src/pkg/xml/xml_test.go +++ b/src/pkg/xml/xml_test.go @@ -94,6 +94,57 @@ var cookedTokens = []Token{ Comment(strings.Bytes(" missing final newline ")), } +var xmlInput = []string{ + // unexpected EOF cases + "<", + "c", + "", + "<>", + "", + "", + // "", // let the Token() caller handle + "", + "", + "", + "", + " c;", + "", + "", + "", + // "", // let the Token() caller handle + "cdata", + "", + "", + "cdata]]>", +} + 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]) + } + } +} -- cgit v1.2.3