From e4457392c6b0de342849f03bd131bc3efccf4fa0 Mon Sep 17 00:00:00 2001 From: Magomed Chemurziev Date: Thu, 24 Oct 2024 17:20:05 +0300 Subject: [PATCH 1/2] fix: empty string in arrayBuffer --- CHANGELOG.md | 6 ++++++ src/core/request/response/CHANGELOG.md | 6 ++++++ src/core/request/response/index.ts | 2 +- src/core/request/response/test/main.spec.ts | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/core/request/response/test/main.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b575ba3a..6f13bc05a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ Changelog _Note: Gaps between patch versions are faulty, broken or test releases._ +## v4.0.0-alpha.?? (2024-??-??) + +#### :bug: Bug Fix + +* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header `core/request/response` + ## v4.0.0-alpha.47.speedup (2024-10-01) #### :boom: Breaking Change diff --git a/src/core/request/response/CHANGELOG.md b/src/core/request/response/CHANGELOG.md index 87b9998c5..75bb71ecd 100644 --- a/src/core/request/response/CHANGELOG.md +++ b/src/core/request/response/CHANGELOG.md @@ -9,6 +9,12 @@ Changelog > - :house: [Internal] > - :nail_care: [Polish] +## v4.0.0-alpha.?? (2024-??-??) + +#### :bug: Bug Fix + +* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header + ## v3.93.0 (2023-03-14) #### :rocket: New Feature diff --git a/src/core/request/response/index.ts b/src/core/request/response/index.ts index ac501a4e8..21ad88aaf 100644 --- a/src/core/request/response/index.ts +++ b/src/core/request/response/index.ts @@ -664,7 +664,7 @@ export default class Response< @once arrayBuffer(): AbortablePromise { return this.readBody().then((body) => { - if (body == null) { + if (body == null || body === '') { return new ArrayBuffer(0); } diff --git a/src/core/request/response/test/main.spec.ts b/src/core/request/response/test/main.spec.ts new file mode 100644 index 000000000..8f0b1418f --- /dev/null +++ b/src/core/request/response/test/main.spec.ts @@ -0,0 +1,19 @@ +import { Response } from 'core/request'; +import V4Headers from 'core/request/headers'; + +describe('core/request/response', () => { + test([ + 'should successfully handle a request with the Content-Type: application/octet-stream header', + 'and an empty response body' + ].join(' '), async () => { + + const response = new Response(Promise.resolve(''), { + url: 'url/url', + headers: new V4Headers({ + 'Content-Type': 'application/octet-stream' + }) + }); + + await expect(response.decode()).resolves.toBeInstanceOf(ArrayBuffer); + }) +}) From 394d15d302886c1f6b674daf9c1094f281f03b55 Mon Sep 17 00:00:00 2001 From: Magomed Chemurziev Date: Thu, 24 Oct 2024 17:44:21 +0300 Subject: [PATCH 2/2] chore: linter --- src/core/request/response/index.ts | 2 +- src/core/request/response/test/main.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/request/response/index.ts b/src/core/request/response/index.ts index 21ad88aaf..e03ee365a 100644 --- a/src/core/request/response/index.ts +++ b/src/core/request/response/index.ts @@ -664,7 +664,7 @@ export default class Response< @once arrayBuffer(): AbortablePromise { return this.readBody().then((body) => { - if (body == null || body === '') { + if (body == null || body === '') { return new ArrayBuffer(0); } diff --git a/src/core/request/response/test/main.spec.ts b/src/core/request/response/test/main.spec.ts index 8f0b1418f..230d95378 100644 --- a/src/core/request/response/test/main.spec.ts +++ b/src/core/request/response/test/main.spec.ts @@ -15,5 +15,5 @@ describe('core/request/response', () => { }); await expect(response.decode()).resolves.toBeInstanceOf(ArrayBuffer); - }) -}) + }); +});