Skip to content

Commit

Permalink
fix: empty string in arrayBuffer (#447)
Browse files Browse the repository at this point in the history
* fix: empty string in arrayBuffer

* chore: linter
  • Loading branch information
ItMaga authored Oct 30, 2024
1 parent 39fd535 commit 887ea5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/core/request/response/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/request/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ export default class Response<
@once
arrayBuffer(): AbortablePromise<ArrayBuffer> {
return this.readBody().then((body) => {
if (body == null) {
if (body == null || body === '') {
return new ArrayBuffer(0);
}

Expand Down
19 changes: 19 additions & 0 deletions src/core/request/response/test/main.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 887ea5e

Please sign in to comment.