@@ -56,7 +56,7 @@ func Test_CachedProgram_FieldAccess(t *testing.T) {
56
56
}
57
57
}
58
58
59
- func Test_Concurent_FieldAccess (t * testing.T ) {
59
+ func Test_Concurrent_FieldAccess (t * testing.T ) {
60
60
g := NewWithT (t )
61
61
62
62
job := func () {
@@ -81,7 +81,7 @@ func Test_Concurent_FieldAccess(t *testing.T) {
81
81
wg .Add (parallelism )
82
82
for i := 0 ; i < parallelism ; i ++ {
83
83
go func () {
84
- if parallelism % 2 == 0 {
84
+ if i % 2 == 0 {
85
85
runtime .LockOSThread ()
86
86
}
87
87
job ()
@@ -91,6 +91,51 @@ func Test_Concurent_FieldAccess(t *testing.T) {
91
91
wg .Wait ()
92
92
}
93
93
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
+
94
139
// TODO add more tests to catch jq processing errors: syntax, input and program run
95
140
96
141
// Uncomment SkipNow to run and catch memory leaks!
0 commit comments