Skip to content

Commit a79eb75

Browse files
committed
fix: prevent infinite loop when fetching a list of results
When fetching a list of results from cloudflare APIs (e.g. when fetching a list of keys in a kv namespace), the api returns a `cursor` that a consumer should use to get the next 'page' of results. It appears this cursor can also be a blank string (while we'd only account for it to be `undefined`). By only accounting for it to be `undefined`, we were infinitely looping through the same page of results and never terminating. This PR fixes it by letting it be a blank string (and `null`, for good measure)
1 parent 9c10098 commit a79eb75

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/wrangler/src/cfetch/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ function throwFetchError(
106106
}
107107

108108
function hasCursor(result_info: unknown): result_info is { cursor: string } {
109-
return (result_info as { cursor: string } | undefined)?.cursor !== undefined;
109+
const cursor = (result_info as { cursor: string } | undefined)?.cursor;
110+
return cursor !== undefined && cursor !== null && cursor !== "";
110111
}

0 commit comments

Comments
 (0)