Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: node-fetch/node-fetch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.6.10
Choose a base ref
...
head repository: node-fetch/node-fetch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.6.11
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on May 9, 2023

  1. Copy the full SHA
    afb36f6 View commit details
Showing with 5 additions and 20 deletions.
  1. +1 −1 package.json
  2. +4 −4 src/body.js
  3. +0 −15 test/test.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
"dependencies": {
"whatwg-url": "^5.0.0"
},
"peerDependencies": {
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
8 changes: 4 additions & 4 deletions src/body.js
Original file line number Diff line number Diff line change
@@ -114,9 +114,9 @@ Body.prototype = {
* @return Promise
*/
json() {
return this.text().then((text) => {
try{
return JSON.parse(text);
return consumeBody.call(this).then((buffer) => {
try {
return JSON.parse(buffer.toString());
} catch (err) {
return Body.Promise.reject(new FetchError(`invalid json response body at ${this.url} reason: ${err.message}`, 'invalid-json'));
}
@@ -129,7 +129,7 @@ Body.prototype = {
* @return Promise
*/
text() {
return consumeBody.call(this).then(buffer => new TextDecoder().decode(buffer));
return consumeBody.call(this).then(buffer => buffer.toString());
},

/**
15 changes: 0 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -2479,21 +2479,6 @@ describe('Response', function () {
expect(res.headers.get('a')).to.equal('1');
});

it('should decode responses containing BOM to json', async () => {
const json = await new Response('\uFEFF{"a":1}').json();
expect(json.a).to.equal(1);
});

it('should decode responses containing BOM to text', async () => {
const text = await new Response('\uFEFF{"a":1}').text();
expect(text).to.equal('{"a":1}');
});

it('should keep BOM when getting raw bytes', async () => {
const ab = await new Response('\uFEFF{"a":1}').arrayBuffer();
expect(ab.byteLength).to.equal(10);
});

it('should support text() method', function() {
const res = new Response('a=1');
return res.text().then(result => {