Skip to content

Commit

Permalink
dump: Skip JQValueEx if there are not options
Browse files Browse the repository at this point in the history
I used to tojson and would crash in binary values are there were
not optins deciding how to format the strinh. Now just treat as utf8 string.
  • Loading branch information
wader committed Jun 7, 2022
1 parent 068be0a commit a64c28d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/interp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ func valueHas(key any, a func(name string) any, b func(key any) any) any {
func toValue(optsFn func() Options, v any) (any, bool) {
switch v := v.(type) {
case JQValueEx:
if optsFn == nil {
return v.JQValueToGoJQ(), true
}
return v.JQValueToGoJQEx(optsFn), true
case gojq.JQValue:
return v.JQValueToGoJQ(), true
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func init() {
false,
opts.Indent,
func(v any) any {
if v, ok := toValue(func() Options { return Options{} }, v); ok {
if v, ok := toValue(nil, v); ok {
return v
}
panic(fmt.Sprintf("toValue not a JQValue value: %#v", v))
Expand Down
1 change: 1 addition & 0 deletions pkg/interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ type Display interface {
}

type JQValueEx interface {
gojq.JQValue
JQValueToGoJQEx(optsFn func() Options) any
}

Expand Down

0 comments on commit a64c28d

Please sign in to comment.