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

Query range with position function #3

Closed
farshidtz opened this issue May 8, 2020 · 2 comments
Closed

Query range with position function #3

farshidtz opened this issue May 8, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@farshidtz
Copy link

Hi,

Thank you for this package.

I am trying to query a range, but the result is wrong when using and operator:

package main

import (
	"fmt"
	"github.com/antchfx/jsonquery"
	"strings"
)

func main() {
	s := `{
		"phoneNumbers": [
		  {
			"type"  : "mobile",
			"number": "0123-4567-0001"
		  },
		  {
			"type"  : "home",
			"number": "0123-4567-0002"
		  },
		  {
			"type"  : "office",
			"number": "0123-4567-0003"
		  },
		  {
			"type"  : "fax",
			"number": "0123-4567-0004"
		  }
		]
	}`
	doc, err := jsonquery.Parse(strings.NewReader(s))
	if err != nil {
		panic(err)
	}

	fmt.Println("print [2,end):")
	for _, n := range jsonquery.Find(doc, "phoneNumbers/*[ position()>=2 ]/number") {
		fmt.Println(n.InnerText())
	}

	fmt.Println("print [2,4):")
	for _, n := range jsonquery.Find(doc, "phoneNumbers/*[ position()>=2 and position()<4 ]/number") {
		fmt.Println(n.InnerText())
	}
	
	fmt.Println("print [2,4):")
	for _, n := range jsonquery.Find(doc, "phoneNumbers/*[ position()<4 and position()>=2 ]/number") {
		fmt.Println(n.InnerText())
	}

}

Output:

print [2,end):
0123-4567-0002
0123-4567-0003
0123-4567-0004
print [2,4):
0123-4567-0002
0123-4567-0003
0123-4567-0004
print [2,4):

Playground

It returns extra entries or nothing at all depending on how you order the operands.

Any idea?

@zhengchun zhengchun added the bug Something isn't working label May 8, 2020
@zhengchun
Copy link
Contributor

I have tested, this bug is by xpath package.

@zhengchun
Copy link
Contributor

fixed in v1.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants