Skip to content

Commit af1076d

Browse files
committed
fix: avoid mutating redirect chain array when formatting
toStringDetailed() and toJSONDetailed() call .reverse() on the array returned by request.redirectChain(), which mutates the original array in-place. Subsequent calls to these methods or any code that reads the redirect chain will see the reversed (incorrect) order. Copy the array before reversing to avoid mutating shared state.
1 parent 8d765c0 commit af1076d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/formatters/NetworkFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class NetworkFormatter {
163163
if (redirectChain.length) {
164164
response.push(`### Redirect chain`);
165165
let indent = 0;
166-
for (const request of redirectChain.reverse()) {
166+
for (const request of [...redirectChain].reverse()) {
167167
const id = this.#options.requestIdResolver
168168
? this.#options.requestIdResolver(request)
169169
: undefined;
@@ -191,7 +191,7 @@ export class NetworkFormatter {
191191

192192
toJSONDetailed(): object {
193193
const redirectChain = this.#request.redirectChain();
194-
const formattedRedirectChain = redirectChain.reverse().map(request => {
194+
const formattedRedirectChain = [...redirectChain].reverse().map(request => {
195195
const id = this.#options.requestIdResolver
196196
? this.#options.requestIdResolver(request)
197197
: undefined;

0 commit comments

Comments
 (0)