Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the wrong Content-Length in python-server.py for non-ascii characters.#24480

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

tomoki
Copy link

@tomokitomoki commentedNov 22, 2024
edited
Loading

Resolves:#24479

python-server.py currently usessys.stdin.read for reading the input, and it receives the length instr (utf-8 string).
ref:https://docs.python.org/3/library/sys.html

On the other "Content-Length" is the size inbytes, therefore we should not passcontent_length tosys.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. Replacesys.stdin.read(content_length) withsys.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.

image

MtkN1 reacted with thumbs up emoji
@vs-code-engineeringvs-code-engineeringbot added this to theNovember 2024 milestoneNov 25, 2024
@karthiknadig
Copy link
Member

Thanks for identifying the issue and providing a fix for it 🚀. We really appreciate it. Happy Coding!!!

tomoki reacted with heart emoji

@karthiknadigkarthiknadigenabled auto-merge (squash)November 25, 2024 05:24
…ters.Content-Length is the data in bytes, not len of str. We should use sys.stdin.buffer.read instead of sys.stdin.read to receive bytes._send_message should calculate "Content-Length" from bytes, not str.
We should use stdin.buffer.readline instead of stdin.readline because stdin.read* and stdin.buffer.read* should be used at the same time.  (stdin.read* refers the internal buffer)
@karthiknadigkarthiknadigforce-pushed thefix-content-length-for-python-repl-server branch fromcd9a0cc to1c8e5f4CompareNovember 26, 2024 06:17
@tomoki
Copy link
Author

Thank you for your review!

Looks like the Github Action failed due to the rate limit exceeded.
https://github.com/microsoft/vscode-python/actions/runs/12024958777/job/33521533822?pr=24480

@karthiknadigkarthiknadig merged commitdba0a4c intomicrosoft:mainNov 26, 2024
46 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@karthiknadigkarthiknadigkarthiknadig approved these changes

@cwebster-99cwebster-99cwebster-99 approved these changes

@anthonykim1anthonykim1Awaiting requested review from anthonykim1

@eleanorjboydeleanorjboydAwaiting requested review from eleanorjboyd

Assignees

@karthiknadigkarthiknadig

Labels
bugIssue identified by VS Code Team member as probable bug
Projects
None yet
Milestone
November 2024
Development

Successfully merging this pull request may close these issues.

"Run Selection/Line in Python REPL" hangs up if the code contains non-ascii characters
4 participants
@tomoki@karthiknadig@cwebster-99@anthonykim1

[8]ページ先頭

©2009-2025 Movatter.jp