Skip to content

Commit ae8f757

Browse files
authored
Merge pull request #452 from V4Fire/shcherbina/handle-empty-string-reponse
fix: empty string in arrayBuffer (#447)
2 parents c896973 + 5f77e00 commit ae8f757

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Changelog
1111
1212
_Note: Gaps between patch versions are faulty, broken or test releases._
1313

14+
## v3.101.2 (2024-12-09)
15+
16+
#### :bug: Bug Fix
17+
18+
* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header `core/request/response`
19+
1420
## v3.101.1 (2024-10-21)
1521

1622
#### :bug: Bug Fix

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "lib/core/index.js",
66
"typings": "index.d.ts",
77
"license": "MIT",
8-
"version": "3.101.1",
8+
"version": "3.101.2",
99
"author": "kobezzza <[email protected]> (https://github.com/kobezzza)",
1010
"repository": {
1111
"type": "git",

src/core/request/response/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v3.101.2 (2024-12-09)
13+
14+
#### :bug: Bug Fix
15+
16+
* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header `core/request/response`
17+
1218
## v3.93.0 (2023-03-14)
1319

1420
#### :rocket: New Feature

src/core/request/response/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ export default class Response<
664664
@once
665665
arrayBuffer(): AbortablePromise<ArrayBuffer> {
666666
return this.readBody().then((body) => {
667-
if (body == null) {
667+
if (body == null || body === '') {
668668
return new ArrayBuffer(0);
669669
}
670670

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Response } from 'core/request';
2+
import V4Headers from 'core/request/headers';
3+
4+
describe('core/request/response', () => {
5+
test([
6+
'should successfully handle a request with the Content-Type: application/octet-stream header',
7+
'and an empty response body'
8+
].join(' '), async () => {
9+
10+
const response = new Response(Promise.resolve(''), {
11+
url: 'url/url',
12+
headers: new V4Headers({
13+
'Content-Type': 'application/octet-stream'
14+
})
15+
});
16+
17+
await expect(response.decode()).resolves.toBeInstanceOf(ArrayBuffer);
18+
});
19+
});

0 commit comments

Comments
 (0)