From e79319d300cd372f6cfdb9e3b5f70dc55d99397f Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 23 Apr 2020 18:35:22 +0200
Subject: [PATCH] fix(cdnjs): handle empty 200 ok response

---
 lib/datasource/cdnjs/index.spec.ts | 6 ++++++
 lib/datasource/cdnjs/index.ts      | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/lib/datasource/cdnjs/index.spec.ts b/lib/datasource/cdnjs/index.spec.ts
index db16b940c8..210f6dfcb9 100644
--- a/lib/datasource/cdnjs/index.spec.ts
+++ b/lib/datasource/cdnjs/index.spec.ts
@@ -40,6 +40,12 @@ describe('datasource/cdnjs', () => {
       got.mockRejectedValueOnce({ statusCode: 404 });
       expect(await getReleases({ lookupName: 'foo/bar' })).toBeNull();
     });
+    it('returns null for empty 200 OK', async () => {
+      got.mockResolvedValueOnce({ body: {} });
+      expect(
+        await getReleases({ lookupName: 'doesnotexist/doesnotexist' })
+      ).toBeNull();
+    });
     it('throws for 401', async () => {
       got.mockRejectedValueOnce({ statusCode: 401 });
       await expect(getReleases({ lookupName: 'foo/bar' })).rejects.toThrowError(
diff --git a/lib/datasource/cdnjs/index.ts b/lib/datasource/cdnjs/index.ts
index c74c1d2e02..7354172a10 100644
--- a/lib/datasource/cdnjs/index.ts
+++ b/lib/datasource/cdnjs/index.ts
@@ -37,6 +37,9 @@ export async function getReleases({
       lookup: library,
       cb: downloadLibrary,
     });
+    if (!assets) {
+      return null;
+    }
     const assetName = lookupName.replace(`${library}/`, '');
     const releases = assets
       .filter(({ files }) => files.includes(assetName))
-- 
GitLab