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

XPath syntax problems should make the query fail before execution #541

Closed
smola opened this issue Oct 5, 2018 · 3 comments
Closed

XPath syntax problems should make the query fail before execution #541

smola opened this issue Oct 5, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@smola
Copy link
Contributor

smola commented Oct 5, 2018

Using double quotes here '//*[@role="Return"]' will make the XPath expression not valid:

gitbase_1      | time="2018-10-05T09:05:33Z" level=warning msg="unable to parse the given blob using bblfsh: rpc error: code = Unknown desc = check: key \"escapedValue\": invalid syntax (\"\\1\")"

It would be good to validate this during analysis and fail.

@smola smola added the enhancement New feature or request label Oct 5, 2018
@kuba-- kuba-- self-assigned this Oct 5, 2018
@kuba--
Copy link
Contributor

kuba-- commented Oct 5, 2018

I'm closing so far. Looks that the problem was during parsing a blob (missed escaped characters).
Bblfsh doesn't complain on any xpath.
If we encounter this kind of issue in the future we can reopen it.
Maybe as a future improvement we can add xpath validator to bblfsh client-go.v3

@kuba-- kuba-- closed this as completed Oct 5, 2018
@bzz
Copy link
Contributor

bzz commented Nov 26, 2018

@kuba-- jfyi there already is an API for validating XPath in SDK

import github.com/bblfsh/sdk/uast/query/xpath

idx := xpath.New()
q, err := idx.Prepare("//uast:Identifier")
if err != nil {
  //handle it
}
q.Execute(uast)

And ofc upon feature request in a new issue it can be exposed in client-go.

@kuba--
Copy link
Contributor

kuba-- commented Nov 28, 2018

@bzz - we've already used a new stuff. Look at my comments: #635

The problem is the 3rd party library (https://github.com/antchfx/xpath/blob/master/xpath.go#L139).
The xpath.Compile (parse) function doesn't validate xpath string (only checks if it's empty/nil or not). For instance following tests passes:

func TestBblfsh(t *testing.T) {
    var err error
    var x *Expr

    x, err = Compile("//*[@role=\"Return\"]")
    if err != nil {
        t.Fatalf("should be correct but got error %s", err)
    }
    t.Logf("%v\n", x)

    x, err = Compile("BAD")
    if err != nil {
        t.Fatalf("should be correct but got error %s", err)
    }
    t.Logf("%v\n", x)

    x, err = Compile("this is a totally crap. For sure not valid @xpath")
    if err != nil {
        t.Fatalf("should be correct but got error %s", err)
    }
    t.Logf("%v\n", x)

    x, err = Compile("//*")
    if err != nil {
        t.Fatalf("should be correct but got error %s", err)
    }
    t.Logf("%v\n", x)

    /*
        x, err = Compile("")
        if err != nil {
            t.Fatalf("should be correct but got error %s", err)
        }
        t.Logf("%v\n", x)
    */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants