Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Jul 1, 2020

Conversation

a631807682
Copy link
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

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
Collaborator

@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

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
Collaborator

@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
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 added this to In progress in v0.20.0 via automation Jul 1, 2020
@jasonsaayman jasonsaayman added this to the v0.20.0 milestone Jul 1, 2020
@jasonsaayman jasonsaayman merged commit 16aa2ce into axios:master Jul 1, 2020
v0.20.0 automation moved this from In progress to Done 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 <jasonsaayman@gmail.com>

* Update mergeConfig.js

Co-authored-by: Yasu Flores <carlosyasu91@gmail.com>
Co-authored-by: Cr <631807682@qq.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
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 <jasonsaayman@gmail.com>

* Update http.js

* Fix trailing spaces

* fix: strip Bom before parse to json

Co-authored-by: Alanscut <948467222@qq.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Co-authored-by: Cr <a631807682@qq.com>
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 <jasonsaayman@gmail.com>
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 <jasonsaayman@gmail.com>
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 <jasonsaayman@gmail.com>

* Update mergeConfig.js

Co-authored-by: Yasu Flores <carlosyasu91@gmail.com>
Co-authored-by: Cr <631807682@qq.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
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 <jasonsaayman@gmail.com>

* Update http.js

* Fix trailing spaces

* fix: strip Bom before parse to json

Co-authored-by: Alanscut <948467222@qq.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Co-authored-by: Cr <a631807682@qq.com>
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 <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v0.20.0
  
Done
Development

Successfully merging this pull request may close these issues.

transfer-encoding chunked not handled for application/json
4 participants