Skip to content

Allow for autodection of encoding for scalar values#5486

Open
blenq wants to merge 4 commits intopsf:mainfrom
blenq:master
Open

Allow for autodection of encoding for scalar values#5486
blenq wants to merge 4 commits intopsf:mainfrom
blenq:master

Conversation

@blenq
Copy link

@blenq blenq commented Jun 10, 2020

Since JSON RFC 7158 (and also in 7159 and 8259) scalar values are also valid JSON texts. The json decoder from the Python standard libs also accepts such scalar values.

The JSON Unicode detection algorithm in "requests" assumes that the first two characters are always ASCII. That is not true anymore.
Therefore the current detection fails in at least these two edge cases

  • A single digit in UTF-16 encoding
  • A quoted string with the first character having a Unicode value higher than 255 in UTF-16 encoding

Also autodetection by chardet returns the wrong encoding.

This change detects the encoding in case of those two edge cases.

@nateprewitt nateprewitt changed the base branch from master to main January 3, 2022 15:26
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.

1 participant