diff --git a/go.mod b/go.mod index 9d79bd2..e6dd2a3 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( ) require ( - github.com/antchfx/xpath v1.3.0 // indirect + github.com/antchfx/xpath v1.3.1 // indirect github.com/fatih/color v1.17.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect diff --git a/go.sum b/go.sum index 30118df..fabdd47 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,8 @@ github.com/antchfx/xmlquery v1.4.0 h1:xg2HkfcRK2TeTbdb0m1jxCYnvsPaGY/oeZWTGqX/0hA= github.com/antchfx/xmlquery v1.4.0/go.mod h1:Ax2aeaeDjfIw3CwXKDQ0GkwZ6QlxoChlIBP+mGnDFjI= -github.com/antchfx/xpath v1.3.0 h1:nTMlzGAK3IJ0bPpME2urTuFL76o4A96iYvoKFHRXJgc= github.com/antchfx/xpath v1.3.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= +github.com/antchfx/xpath v1.3.1 h1:PNbFuUqHwWl0xRjvUPjJ95Agbmdj2uzzIwmQKgu4oCk= +github.com/antchfx/xpath v1.3.1/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0= github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA= github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo= diff --git a/vendor/github.com/antchfx/xpath/build.go b/vendor/github.com/antchfx/xpath/build.go index e079e96..44f87d8 100644 --- a/vendor/github.com/antchfx/xpath/build.go +++ b/vendor/github.com/antchfx/xpath/build.go @@ -665,7 +665,7 @@ func (b *builder) processOperator(root *operatorNode, props *builderProp) (query var qyOutput query switch root.Op { case "+", "-", "*", "div", "mod": // Numeric operator - var exprFunc func(interface{}, interface{}) interface{} + var exprFunc func(iterator, interface{}, interface{}) interface{} switch root.Op { case "+": exprFunc = plusFunc diff --git a/vendor/github.com/antchfx/xpath/func.go b/vendor/github.com/antchfx/xpath/func.go index 65386f0..a5e88ba 100644 --- a/vendor/github.com/antchfx/xpath/func.go +++ b/vendor/github.com/antchfx/xpath/func.go @@ -113,7 +113,7 @@ func asNumber(t iterator, o interface{}) float64 { case query: node := typ.Select(t) if node == nil { - return float64(0) + return math.NaN() } if v, err := strconv.ParseFloat(node.Value(), 64); err == nil { return v diff --git a/vendor/github.com/antchfx/xpath/operator.go b/vendor/github.com/antchfx/xpath/operator.go index 12aadc1..2820152 100644 --- a/vendor/github.com/antchfx/xpath/operator.go +++ b/vendor/github.com/antchfx/xpath/operator.go @@ -1,7 +1,6 @@ package xpath import ( - "reflect" "strconv" ) @@ -247,44 +246,43 @@ var orFunc = func(t iterator, m, n interface{}) interface{} { return logicalFuncs[t1][t2](t, "or", m, n) } -func numericExpr(m, n interface{}, cb func(float64, float64) float64) float64 { - typ := reflect.TypeOf(float64(0)) - a := reflect.ValueOf(m).Convert(typ) - b := reflect.ValueOf(n).Convert(typ) - return cb(a.Float(), b.Float()) +func numericExpr(t iterator, m, n interface{}, cb func(float64, float64) float64) float64 { + a := asNumber(t, m) + b := asNumber(t, n) + return cb(a, b) } // plusFunc is an `+` operator. -var plusFunc = func(m, n interface{}) interface{} { - return numericExpr(m, n, func(a, b float64) float64 { +var plusFunc = func(t iterator, m, n interface{}) interface{} { + return numericExpr(t, m, n, func(a, b float64) float64 { return a + b }) } // minusFunc is an `-` operator. -var minusFunc = func(m, n interface{}) interface{} { - return numericExpr(m, n, func(a, b float64) float64 { +var minusFunc = func(t iterator, m, n interface{}) interface{} { + return numericExpr(t, m, n, func(a, b float64) float64 { return a - b }) } // mulFunc is an `*` operator. -var mulFunc = func(m, n interface{}) interface{} { - return numericExpr(m, n, func(a, b float64) float64 { +var mulFunc = func(t iterator, m, n interface{}) interface{} { + return numericExpr(t, m, n, func(a, b float64) float64 { return a * b }) } // divFunc is an `DIV` operator. -var divFunc = func(m, n interface{}) interface{} { - return numericExpr(m, n, func(a, b float64) float64 { +var divFunc = func(t iterator, m, n interface{}) interface{} { + return numericExpr(t, m, n, func(a, b float64) float64 { return a / b }) } // modFunc is an 'MOD' operator. -var modFunc = func(m, n interface{}) interface{} { - return numericExpr(m, n, func(a, b float64) float64 { +var modFunc = func(t iterator, m, n interface{}) interface{} { + return numericExpr(t, m, n, func(a, b float64) float64 { return float64(int(a) % int(b)) }) } diff --git a/vendor/github.com/antchfx/xpath/query.go b/vendor/github.com/antchfx/xpath/query.go index fe6f488..a4d1dce 100644 --- a/vendor/github.com/antchfx/xpath/query.go +++ b/vendor/github.com/antchfx/xpath/query.go @@ -999,7 +999,7 @@ func (l *logicalQuery) Properties() queryProp { type numericQuery struct { Left, Right query - Do func(interface{}, interface{}) interface{} + Do func(iterator, interface{}, interface{}) interface{} } func (n *numericQuery) Select(t iterator) NodeNavigator { @@ -1009,7 +1009,7 @@ func (n *numericQuery) Select(t iterator) NodeNavigator { func (n *numericQuery) Evaluate(t iterator) interface{} { m := n.Left.Evaluate(t) k := n.Right.Evaluate(t) - return n.Do(m, k) + return n.Do(t, m, k) } func (n *numericQuery) Clone() query { diff --git a/vendor/github.com/antchfx/xpath/xpath.go b/vendor/github.com/antchfx/xpath/xpath.go index aa27370..04bbe8d 100644 --- a/vendor/github.com/antchfx/xpath/xpath.go +++ b/vendor/github.com/antchfx/xpath/xpath.go @@ -74,7 +74,6 @@ type NodeNavigator interface { type NodeIterator struct { node NodeNavigator query query - table map[uint64]bool } // Current returns current node which matched. @@ -84,22 +83,14 @@ func (t *NodeIterator) Current() NodeNavigator { // MoveNext moves Navigator to the next match node. func (t *NodeIterator) MoveNext() bool { - for { - n := t.query.Select(t) - if n == nil { - return false - } - if !t.node.MoveTo(n) { - t.node = n.Copy() - } - // https://github.com/antchfx/xpath/issues/94 - id := getHashCode(n.Copy()) - if _, ok := t.table[id]; ok { - continue - } - t.table[id] = true - return true + n := t.query.Select(t) + if n == nil { + return false } + if !t.node.MoveTo(n) { + t.node = n.Copy() + } + return true } // Select selects a node set using the specified XPath expression. @@ -130,14 +121,14 @@ func (expr *Expr) Evaluate(root NodeNavigator) interface{} { val := expr.q.Evaluate(iteratorFunc(func() NodeNavigator { return root })) switch val.(type) { case query: - return &NodeIterator{query: expr.q.Clone(), node: root, table: make(map[uint64]bool)} + return &NodeIterator{query: expr.q.Clone(), node: root} } return val } // Select selects a node set using the specified XPath expression. func (expr *Expr) Select(root NodeNavigator) *NodeIterator { - return &NodeIterator{query: expr.q.Clone(), node: root, table: make(map[uint64]bool)} + return &NodeIterator{query: expr.q.Clone(), node: root} } // String returns XPath expression string. diff --git a/vendor/modules.txt b/vendor/modules.txt index ed43433..47b4b4a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ # github.com/antchfx/xmlquery v1.4.0 ## explicit; go 1.14 github.com/antchfx/xmlquery -# github.com/antchfx/xpath v1.3.0 +# github.com/antchfx/xpath v1.3.1 ## explicit; go 1.14 github.com/antchfx/xpath # github.com/apex/log v1.9.0