Skip to content

Commit 015c0e1

Browse files
authored
add depth check to prevent stackoverflow (#925)
* add depth check to prevent stackoverflow * fix format
1 parent 5028562 commit 015c0e1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/testing/src/check.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ export class Checker {
179179
return '(number)'
180180
}
181181

182-
const process = (obj: any): any => {
182+
const process = (obj: any, depth: number): any => {
183+
if (depth <= 0) {
184+
return obj
185+
}
183186
if (obj == null) {
184187
return obj
185188
}
186189
if (Array.isArray(obj)) {
187-
return obj.map(process)
190+
return obj.map((x) => process(x, depth - 1))
188191
}
189192
if (redactNumber && typeof obj === 'number') {
190193
return processNumber(obj)
@@ -223,14 +226,14 @@ export class Checker {
223226
if (this.#redactOptions?.redactKeys?.test(k)) {
224227
return [k, '(redacted)']
225228
}
226-
return [k, process(v)]
229+
return [k, process(v, depth - 1)]
227230
}),
228231
)
229232
}
230233
return obj
231234
}
232235

233-
return process(value)
236+
return process(value, 50)
234237
}
235238

236239
/**

0 commit comments

Comments
 (0)