Skip to content

Fixing response with utf-8 BOM can not parse to json#2419

Merged
jasonsaayman merged 5 commits intoaxios:masterfrom
a631807682:master
Jul 1, 2020
Merged

Fixing response with utf-8 BOM can not parse to json#2419
jasonsaayman merged 5 commits intoaxios:masterfrom
a631807682:master

Conversation

@a631807682
Copy link
Copy Markdown
Contributor

@a631807682 a631807682 commented Sep 19, 2019

Some services(deploy on Windows) will response data with BOM that can not parse it to json.

see #1768 (comment)

@Morgul
Copy link
Copy Markdown

Morgul commented Feb 11, 2020

Just saying I'd love to see this merged as I have to use an annoying workaround to use Axios with our legacy .Net services. (They all return a BOM character.)

@chinesedfan
Copy link
Copy Markdown
Contributor

@Morgul I think you can solve it by add another transformRequest before the default. Just remove those annoying characters in yourTransformRequest.

axios(url, {
  transformRequest: [yourTransformRequest].concat(axios.defaults.transformRequest)
}

@Morgul
Copy link
Copy Markdown

Morgul commented Feb 26, 2020

@chinesedfan That works, as a work around, but I'd love to see this merged in, as axios is one of the few libraries that doesn't automatically work around this issue. 🙁

@chinesedfan
Copy link
Copy Markdown
Contributor

@Morgul Would you mind to list some examples? I am glad to check their implementations. And also make preparations for some users who want to keep those BOMs.

@a631807682
Copy link
Copy Markdown
Contributor Author

@chinesedfan Here are some examples to avoid these problems. (Windows system save file with BOM, but not all HTTP services handle it)
request/request.js#L1135
node/lib/internal/modules/cjs/helpers.js#L105

@jasonsaayman jasonsaayman merged commit 16aa2ce into axios:master Jul 1, 2020
jasonsaayman added a commit that referenced this pull request Jul 1, 2020
* add checkServerIdentity to request config for http adapter

* add checkServerIdentity unit test

* add checkServerIdentity doc

* add more unit tests for checkServerIdentity

* remove ssl-root-cas dependency

* add changes description to changelog

* Fixing response with utf-8 BOM can not parse to json (#2419)

* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>

* Update mergeConfig.js

Co-authored-by: Yasu Flores <[email protected]>
Co-authored-by: Cr <[email protected]>
Co-authored-by: Jay <[email protected]>
jasonsaayman added a commit that referenced this pull request Jul 2, 2020
* fix: only set responseType 'json' or use defaulte responseType return
JSON response

* test: change defalut transform behaviour

* refactor: try to parse json

* fix: code style

* test: response type json

* fix: set default transformResponse to empty array

* chore: code style

* Fixing response with utf-8 BOM can not parse to json (#2419)

* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>

* Update http.js

* Fix trailing spaces

* fix: strip Bom before parse to json

Co-authored-by: Alanscut <[email protected]>
Co-authored-by: Jay <[email protected]>
Co-authored-by: Cr <[email protected]>
gwdp pushed a commit to ikon-integration/axios that referenced this pull request Jul 17, 2020
* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>
gwdp pushed a commit to ikon-integration/axios that referenced this pull request Jul 17, 2020
* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>
IvanStoilov pushed a commit to IvanStoilov/axios that referenced this pull request Nov 25, 2020
* add checkServerIdentity to request config for http adapter

* add checkServerIdentity unit test

* add checkServerIdentity doc

* add more unit tests for checkServerIdentity

* remove ssl-root-cas dependency

* add changes description to changelog

* Fixing response with utf-8 BOM can not parse to json (axios#2419)

* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>

* Update mergeConfig.js

Co-authored-by: Yasu Flores <[email protected]>
Co-authored-by: Cr <[email protected]>
Co-authored-by: Jay <[email protected]>
IvanStoilov pushed a commit to IvanStoilov/axios that referenced this pull request Nov 25, 2020
* fix: only set responseType 'json' or use defaulte responseType return
JSON response

* test: change defalut transform behaviour

* refactor: try to parse json

* fix: code style

* test: response type json

* fix: set default transformResponse to empty array

* chore: code style

* Fixing response with utf-8 BOM can not parse to json (axios#2419)

* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>

* Update http.js

* Fix trailing spaces

* fix: strip Bom before parse to json

Co-authored-by: Alanscut <[email protected]>
Co-authored-by: Jay <[email protected]>
Co-authored-by: Cr <[email protected]>
mbargiel pushed a commit to mbargiel/axios that referenced this pull request Jan 27, 2022
* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transfer-encoding chunked not handled for application/json

4 participants