Skip to content

Commit

Permalink
respect text encoding specified in argument (#20999)
Browse files Browse the repository at this point in the history
* respect text encoding specified in argument

* update
  • Loading branch information
xiangyan99 authored Oct 5, 2021
1 parent 139aae2 commit 253dab8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- respect text encoding specified in argument (thanks to @ryohji for the contribution) #20796

### Other Changes

## 1.19.0 (2021-09-30)
Expand Down
6 changes: 4 additions & 2 deletions sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ def text(self, encoding: Optional[str] = None) -> str:
ctype = self.headers.get(aiohttp.hdrs.CONTENT_TYPE, "").lower()
mimetype = aiohttp.helpers.parse_mimetype(ctype)

encoding = mimetype.parameters.get("charset")
if not encoding:
# extract encoding from mimetype, if caller does not specify
encoding = mimetype.parameters.get("charset")
if encoding:
try:
codecs.lookup(encoding)
Expand All @@ -372,7 +374,7 @@ def text(self, encoding: Optional[str] = None) -> str:
)
else:
encoding = chardet.detect(body)["encoding"]
if not encoding:
if encoding == "utf-8" or encoding is None:
encoding = "utf-8-sig"

return body.decode(encoding)
Expand Down

0 comments on commit 253dab8

Please sign in to comment.