Skip to content

Commit 2db4370

Browse files
ItMagaAlexei Shcherbina
authored andcommitted
fix: empty string in arrayBuffer (#447)
* fix: empty string in arrayBuffer * chore: linter
1 parent c896973 commit 2db4370

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
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.?? (2024-??-??)
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

src/core/request/response/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Changelog
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111
12+
## v3.101.?? (2024-??-??)
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 19 additions & 0 deletions
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)