Skip to content

Commit 27e93c1

Browse files
authored
Merge pull request #9 from flant/fix_nassert_trace
fix: try+fromjson crashes subsequent executions
2 parents 488a771 + 8226fe0 commit 27e93c1

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

modules/jq

Submodule jq updated from bda75c3 to 2e01ff1

modules/oniguruma

Submodule oniguruma updated 147 files

pkg/jq/jq_test.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Test_CachedProgram_FieldAccess(t *testing.T) {
5656
}
5757
}
5858

59-
func Test_Concurent_FieldAccess(t *testing.T) {
59+
func Test_Concurrent_FieldAccess(t *testing.T) {
6060
g := NewWithT(t)
6161

6262
job := func() {
@@ -81,7 +81,7 @@ func Test_Concurent_FieldAccess(t *testing.T) {
8181
wg.Add(parallelism)
8282
for i := 0; i < parallelism; i++ {
8383
go func() {
84-
if parallelism%2 == 0 {
84+
if i%2 == 0 {
8585
runtime.LockOSThread()
8686
}
8787
job()
@@ -91,6 +91,51 @@ func Test_Concurent_FieldAccess(t *testing.T) {
9191
wg.Wait()
9292
}
9393

94+
// NOTE 02.02.2020 This test crashes with SIGABRT and trace when use jq from master
95+
// jq and oniguruma are downgraded to jq-1.6 tag
96+
//
97+
// Use case is to get normal literals as well as json encoded objects from base64 encoded values.
98+
// (.data | [to_entries[] | (.value |= (. | @base64d))] | from_entries)
99+
// +
100+
// (.data | [to_entries[] | try(.value |= (. | @base64d | fromjson))] | from_entries)
101+
//
102+
// Crash is happened when there is only try portion and fromjson is used.
103+
//
104+
func Test_jq_errors_inside_try_crash_subsequent_runs(t *testing.T) {
105+
106+
var r string
107+
var err error
108+
109+
r, err = NewJq().WithCache(JqDefaultCache()).
110+
Program(`.foo`).
111+
Run(`{"foo":"baz"}`)
112+
if err != nil {
113+
t.Errorf("1: %s", err)
114+
}
115+
fmt.Println(r)
116+
117+
r, err = NewJq().WithCache(JqDefaultCache()).
118+
Program(`
119+
try(.data.b64String |= (. | fromjson)) catch .
120+
`).
121+
Run(`
122+
{ "data":{"b64JSON":"eyJwYXJzZSI6Im1lIn0=","b64String":"YWJj","jsonStr":"{\"foo\":\"bar\"}"} }`)
123+
124+
if err != nil {
125+
t.Errorf("2: %s", err)
126+
}
127+
fmt.Println(r)
128+
129+
// This call crashes with trace on jq master
130+
r, err = NewJq().WithCache(JqDefaultCache()).
131+
Program(`.foo`).
132+
Run(`{"foo":"bar"}`)
133+
if err != nil {
134+
t.Errorf("3: %s", err)
135+
}
136+
fmt.Println(r)
137+
}
138+
94139
// TODO add more tests to catch jq processing errors: syntax, input and program run
95140

96141
// Uncomment SkipNow to run and catch memory leaks!

0 commit comments

Comments
 (0)