Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when querying malformed xpath #31

Open
WithoutPants opened this issue Jul 13, 2020 · 0 comments
Open

Panic when querying malformed xpath #31

WithoutPants opened this issue Jul 13, 2020 · 0 comments

Comments

@WithoutPants
Copy link

Added the following to TestXPath in query_test.go:

_, err := QueryAll(testDoc, "$test/@attr")

I'd expect this to return an error during parsing due to the badly formed xpath. Instead, it causes a panic:

--- FAIL: TestXPath (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x543fd5]

goroutine 15 [running]:
testing.tRunner.func1.1(0x7423c0, 0xaee130)
        c:/go/src/testing/testing.go:940 +0x2fc
testing.tRunner.func1(0xc000111200)
        c:/go/src/testing/testing.go:943 +0x400
panic(0x7423c0, 0xaee130)
        c:/go/src/runtime/panic.go:969 +0x174
github.com/antchfx/xpath.(*attributeQuery).Clone(0xc0000054c0, 0xc000005520, 0x728220)
        C:/Users/.../go/pkg/mod/github.com/antchfx/[email protected]/query.go:164 +0x35
github.com/antchfx/xpath.(*Expr).Select(...)
        C:/Users/.../go/pkg/mod/github.com/antchfx/[email protected]/xpath.go:131
github.com/antchfx/htmlquery.QuerySelectorAll(0xc00010a230, 0xc0000054e0, 0xc0000054e0, 0x0, 0x0)
        D:/dev/htmlquery/query.go:82 +0x91
github.com/antchfx/htmlquery.QueryAll(0xc00010a230, 0x7ad043, 0xb, 0xc000191500, 0x0, 0x0, 0xa2b565, 0x1c)
        D:/dev/htmlquery/query.go:54 +0x8c
github.com/antchfx/htmlquery.TestXPath(0xc000111200)
        D:/dev/htmlquery/query_test.go:150 +0x2c1
testing.tRunner(0xc000111200, 0x7cbd00)
        c:/go/src/testing/testing.go:991 +0xe3
created by testing.(*T).Run
        c:/go/src/testing/testing.go:1042 +0x35e
exit status 2
FAIL    github.com/antchfx/htmlquery    0.270s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants