Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit afb36f6

Browse filesBrowse files
authored
Revert "fix: handle bom in text and json (#1739)" (#1741)
This reverts commit 29909d7.
1 parent 29909d7 commit afb36f6
Copy full SHA for afb36f6

File tree

Expand file treeCollapse file tree

3 files changed

+5
-20
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+5
-20
lines changed

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"whatwg-url": "^5.0.0"
4141
},
42-
"peerDependencies": {
42+
"peerDependencies": {
4343
"encoding": "^0.1.0"
4444
},
4545
"peerDependenciesMeta": {

‎src/body.js

Copy file name to clipboardExpand all lines: src/body.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ Body.prototype = {
114114
* @return Promise
115115
*/
116116
json() {
117-
return this.text().then((text) => {
118-
try{
119-
return JSON.parse(text);
117+
return consumeBody.call(this).then((buffer) => {
118+
try {
119+
return JSON.parse(buffer.toString());
120120
} catch (err) {
121121
return Body.Promise.reject(new FetchError(`invalid json response body at ${this.url} reason: ${err.message}`, 'invalid-json'));
122122
}
@@ -129,7 +129,7 @@ Body.prototype = {
129129
* @return Promise
130130
*/
131131
text() {
132-
return consumeBody.call(this).then(buffer => new TextDecoder().decode(buffer));
132+
return consumeBody.call(this).then(buffer => buffer.toString());
133133
},
134134

135135
/**

‎test/test.js

Copy file name to clipboardExpand all lines: test/test.js
-15Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,21 +2479,6 @@ describe('Response', function () {
24792479
expect(res.headers.get('a')).to.equal('1');
24802480
});
24812481

2482-
it('should decode responses containing BOM to json', async () => {
2483-
const json = await new Response('\uFEFF{"a":1}').json();
2484-
expect(json.a).to.equal(1);
2485-
});
2486-
2487-
it('should decode responses containing BOM to text', async () => {
2488-
const text = await new Response('\uFEFF{"a":1}').text();
2489-
expect(text).to.equal('{"a":1}');
2490-
});
2491-
2492-
it('should keep BOM when getting raw bytes', async () => {
2493-
const ab = await new Response('\uFEFF{"a":1}').arrayBuffer();
2494-
expect(ab.byteLength).to.equal(10);
2495-
});
2496-
24972482
it('should support text() method', function() {
24982483
const res = new Response('a=1');
24992484
return res.text().then(result => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.