forked fromDonJayamanne/pythonVSCode
- Notifications
You must be signed in to change notification settings - Fork1.2k
Commitdba0a4c
authored
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 theinput, and it receives the length in `str` (utf-8 string).ref:https://docs.python.org/3/library/sys.htmlOn the other "Content-Length" is the size in **bytes**, therefore weshould 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.1 parent42b63b9 commitdba0a4c
1 file changed
+9
-5
lines changedLines changed: 9 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
17 |
| - | |
| 17 | + | |
| 18 | + | |
18 | 19 |
| |
19 | 20 |
| |
20 | 21 |
| |
| |||
55 | 56 |
| |
56 | 57 |
| |
57 | 58 |
| |
| 59 | + | |
58 | 60 |
| |
59 | 61 |
| |
60 | 62 |
| |
61 |
| - | |
| 63 | + | |
62 | 64 |
| |
63 | 65 |
| |
64 | 66 |
| |
| |||
74 | 76 |
| |
75 | 77 |
| |
76 | 78 |
| |
| 79 | + | |
77 | 80 |
| |
78 | 81 |
| |
79 | 82 |
| |
80 |
| - | |
| 83 | + | |
81 | 84 |
| |
82 | 85 |
| |
83 | 86 |
| |
| |||
160 | 163 |
| |
161 | 164 |
| |
162 | 165 |
| |
163 |
| - | |
| 166 | + | |
164 | 167 |
| |
165 | 168 |
| |
166 | 169 |
| |
| |||
172 | 175 |
| |
173 | 176 |
| |
174 | 177 |
| |
| 178 | + | |
175 | 179 |
| |
176 | 180 |
| |
177 | 181 |
| |
178 |
| - | |
| 182 | + | |
179 | 183 |
| |
180 | 184 |
| |
181 | 185 |
| |
|
0 commit comments
Comments
(0)