Skip to content

No error or panic when parsing non-XML #86

Description

@tuan-nxcr

I was expecting Parse or Query to error out if I were to pass in something completely invalid, but it falls all the way through instead:

func TestXmlParse_1(t *testing.T) {
	//s := `<note>
	//<to>John</to>
	//<from>Smith</from>
	//<heading>Reminder</heading>
	//<body>Don't forget me this weekend!</body>
	//</note>`

	s := `{"NotXml":"ActuallyJson"}`

	parse, err := xmlquery.Parse(strings.NewReader(s))
	if err != nil {
		println(err.Error())
		t.Fail()
	}
	query, err := xmlquery.Query(parse, "//body/text()")
	if err != nil {
		println(err.Error())
		t.Fail()
	}
	println(query.Data)

}

using:

  • github.com/antchfx/xmlquery v1.3.11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions