Skip to content

Commit

Permalink
Merge pull request #452 from V4Fire/shcherbina/handle-empty-string-re…
Browse files Browse the repository at this point in the history
…ponse

fix: empty string in arrayBuffer (#447)
  • Loading branch information
gretzkiy authored Dec 9, 2024
2 parents c896973 + 5f77e00 commit ae8f757
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
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._

## v3.101.2 (2024-12-09)

#### :bug: Bug Fix

* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header `core/request/response`

## v3.101.1 (2024-10-21)

#### :bug: Bug Fix
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/core/index.js",
"typings": "index.d.ts",
"license": "MIT",
"version": "3.101.1",
"version": "3.101.2",
"author": "kobezzza <[email protected]> (https://github.com/kobezzza)",
"repository": {
"type": "git",
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]
## v3.101.2 (2024-12-09)

#### :bug: Bug Fix

* Fixed an issue when receiving an empty string with the `Content-Type: application/octet-stream` header `core/request/response`

## 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 ae8f757

Please sign in to comment.