Skip to content

Default pagination.paginate function doesn't check for empty string link headers #1741

@joshua-leyshon-canva

Description

@joshua-leyshon-canva

Describe the bug

  • Node.js version: v12.22.1
  • OS & version: MacOS Big Sur, Ubuntu 20

Sometimes (e.g. with Buildkite REST API), a response can contain a link header that is an empty string. The default paginate logic (see just below) doesn't handle this case and will throw when it tries to parse the string. This means we need to add our own paginate logic that is almost identical to the default.

Current default function:

if (typeof response.headers.link !== 'string') {

A fix:

if (typeof response.headers.link !== 'string' || response.headers.link === '') {
  return false;
}

Actual behavior

got throws when parsing an empty string link header.

Expected behavior

The default pagination.paginate function should return false when the link header is an empty string.

Code to reproduce

const res = got.paginate.all('https://somewebsite.com/that-returns-empty-link-header');
// An example endpoint (requires Buildkite authentication):
// "https://api.buildkite.com/v2/organizations/{org.slug}/pipelines/{pipeline.slug}/builds/{build.number}/jobs/{job.id}/artifacts"

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Got.
  • I have tried my code with the latest version of Node.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions