diff --git a/pkg/jsonpath/parser.go b/pkg/jsonpath/parser.go index af233cd..e7e2d0b 100644 --- a/pkg/jsonpath/parser.go +++ b/pkg/jsonpath/parser.go @@ -8,7 +8,7 @@ import ( "strings" ) -const MaxSafeFloat = 9007199254740991 +const MaxSafeFloat int64 = 9007199254740991 type mode int @@ -209,14 +209,14 @@ func (p *JSONPath) parseSelector() (retSelector *selector, err error) { if err != nil { return nil, p.parseFailure(&p.tokens[p.current], "expected an integer") } - err = p.checkSafeInteger(int(i), lit) + err = p.checkSafeInteger(i, lit) if err != nil { return nil, err } p.current++ - return &selector{kind: selectorSubKindArrayIndex, index: int(i)}, nil + return &selector{kind: selectorSubKindArrayIndex, index: i}, nil } else if p.tokens[p.current].Token == token.ARRAY_SLICE { slice, err := p.parseSliceSelector() if err != nil { @@ -232,12 +232,12 @@ func (p *JSONPath) parseSelector() (retSelector *selector, err error) { func (p *JSONPath) parseSliceSelector() (*slice, error) { // slice-selector = [start S] ":" S [end S] [":" [S step]] - var start, end, step *int + var start, end, step *int64 // parse the start index if p.tokens[p.current].Token == token.INTEGER { literal := p.tokens[p.current].Literal - i, err := strconv.Atoi(literal) + i, err := strconv.ParseInt(literal, 10, 64) if err != nil { return nil, p.parseFailure(&p.tokens[p.current], "expected an integer") } @@ -259,7 +259,7 @@ func (p *JSONPath) parseSliceSelector() (*slice, error) { // parse the end index if p.tokens[p.current].Token == token.INTEGER { literal := p.tokens[p.current].Literal - i, err := strconv.Atoi(literal) + i, err := strconv.ParseInt(literal, 10, 64) if err != nil { return nil, p.parseFailure(&p.tokens[p.current], "expected an integer") } @@ -277,7 +277,7 @@ func (p *JSONPath) parseSliceSelector() (*slice, error) { p.current++ if p.tokens[p.current].Token == token.INTEGER { literal := p.tokens[p.current].Literal - i, err := strconv.Atoi(literal) + i, err := strconv.ParseInt(literal, 10, 64) if err != nil { return nil, p.parseFailure(&p.tokens[p.current], "expected an integer") } @@ -297,7 +297,7 @@ func (p *JSONPath) parseSliceSelector() (*slice, error) { return &slice{start: start, end: end, step: step}, nil } -func (p *JSONPath) checkSafeInteger(i int, literal string) error { +func (p *JSONPath) checkSafeInteger(i int64, literal string) error { if i > MaxSafeFloat || i < -MaxSafeFloat { return p.parseFailure(&p.tokens[p.current], "outside bounds for safe integers") } diff --git a/pkg/jsonpath/selector.go b/pkg/jsonpath/selector.go index 401b976..f71cb47 100644 --- a/pkg/jsonpath/selector.go +++ b/pkg/jsonpath/selector.go @@ -17,15 +17,15 @@ const ( ) type slice struct { - start *int - end *int - step *int + start *int64 + end *int64 + step *int64 } type selector struct { kind selectorSubKind name string - index int + index int64 slice *slice filter *filterSelector } @@ -36,7 +36,7 @@ func (s selector) ToString() string { return "'" + escapeString(s.name) + "'" case selectorSubKindArrayIndex: // int to string - return strconv.Itoa(s.index) + return strconv.FormatInt(s.index, 10) case selectorSubKindFilter: return "?" + s.filter.ToString() case selectorSubKindWildcard: @@ -44,16 +44,16 @@ func (s selector) ToString() string { case selectorSubKindArraySlice: builder := strings.Builder{} if s.slice.start != nil { - builder.WriteString(strconv.Itoa(*s.slice.start)) + builder.WriteString(strconv.FormatInt(*s.slice.start, 10)) } builder.WriteString(":") if s.slice.end != nil { - builder.WriteString(strconv.Itoa(*s.slice.end)) + builder.WriteString(strconv.FormatInt(*s.slice.end, 10)) } if s.slice.step != nil { builder.WriteString(":") - builder.WriteString(strconv.Itoa(*s.slice.step)) + builder.WriteString(strconv.FormatInt(*s.slice.step, 10)) } return builder.String() default: diff --git a/pkg/jsonpath/yaml_query.go b/pkg/jsonpath/yaml_query.go index fa6684a..c607938 100644 --- a/pkg/jsonpath/yaml_query.go +++ b/pkg/jsonpath/yaml_query.go @@ -132,12 +132,12 @@ func (s selector) Query(value *yaml.Node, root *yaml.Node) []*yaml.Node { return nil } // if out of bounds, return nothing - if s.index >= len(value.Content) || s.index < -len(value.Content) { + if s.index >= int64(len(value.Content)) || s.index < -int64(len(value.Content)) { return nil } // if index is negative, go backwards if s.index < 0 { - return []*yaml.Node{value.Content[len(value.Content)+s.index]} + return []*yaml.Node{value.Content[int64(len(value.Content))+s.index]} } return []*yaml.Node{value.Content[s.index]} case selectorSubKindWildcard: @@ -160,7 +160,7 @@ func (s selector) Query(value *yaml.Node, root *yaml.Node) []*yaml.Node { if len(value.Content) == 0 { return nil } - step := 1 + step := int64(1) if s.slice.step != nil { step = *s.slice.step } @@ -169,7 +169,7 @@ func (s selector) Query(value *yaml.Node, root *yaml.Node) []*yaml.Node { } start, end := s.slice.start, s.slice.end - lower, upper := bounds(start, end, step, len(value.Content)) + lower, upper := bounds(start, end, step, int64(len(value.Content))) var result []*yaml.Node if step > 0 { @@ -204,15 +204,15 @@ func (s selector) Query(value *yaml.Node, root *yaml.Node) []*yaml.Node { return nil } -func normalize(i, length int) int { +func normalize(i, length int64) int64 { if i >= 0 { return i } return length + i } -func bounds(start, end *int, step, length int) (int, int) { - var nStart, nEnd int +func bounds(start, end *int64, step, length int64) (int64, int64) { + var nStart, nEnd int64 if start != nil { nStart = normalize(*start, length) } else if step > 0 { @@ -228,7 +228,7 @@ func bounds(start, end *int, step, length int) (int, int) { nEnd = -1 } - var lower, upper int + var lower, upper int64 if step >= 0 { lower = max(min(nStart, length), 0) upper = min(max(nEnd, 0), length) diff --git a/web/src/assets/wasm/lib.wasm b/web/src/assets/wasm/lib.wasm index c5d6c70..d533891 100755 Binary files a/web/src/assets/wasm/lib.wasm and b/web/src/assets/wasm/lib.wasm differ