You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix the wrong Content-Length in python-server.py for non-ascii characters. (#24480)
Resolves: #24479
`python-server.py` currently uses `sys.stdin.read` for reading the
input, and it receives the length in `str` (utf-8 string).
ref: https://docs.python.org/3/library/sys.html
On the other "Content-Length" is the size in **bytes**, therefore we
should not pass `content_length` to `sys.stdin.read`. For example,
`print("こんにちは世界")`'s length is 16 in str, but 30 in bytes.
```
>>> len('print("こんにちは世界")')
16
>>> len('print("こんにちは世界")'.encode())
30
```
This PR have two changes.
1. Replace `sys.stdin.read(content_length)` with
`sys.stdin.buffer.read(content_length).decode()`.
2. Make `_send_message` calculate "Content-Length" from bytes, not str.
By these changes, original issue
#24479 can be resolved.

0 commit comments