-
Notifications
You must be signed in to change notification settings - Fork 19.9k
fix: fix http node content decode #31728
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @fatelei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where HTTP response content, particularly with Chinese characters, was being incorrectly decoded due to Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a robust fix for decoding HTTP response content, specifically addressing the ambiguity between Chinese (GBK) and Korean (CP949) encodings. The new safe_decode function is a clever approach that evaluates multiple encoding candidates and scores them to find the best fit. The logic is sound and is backed by a comprehensive set of unit tests. My review identifies a couple of minor improvements in the new api/libs/encode.py file to enhance readability and simplify the code. Overall, this is a high-quality contribution that effectively solves a tricky encoding problem.
bcc4295 to
b10a5f3
Compare
Important
Fixes #<issue number>.Summary
fix #31695
because cp949 and gbk structural overlap
so use the charset_normalizer may detect chinese as korean, the output will be wrong
when httpx response has charset, use the origin httpx response content, if it missing, use charset_normalizer to guess the encoding.
Candidate List and Orthogonal Evaluation
define a clear list of candidates with corresponding scoring functions, then perform "orthogonal evaluation" on them (scoring each independently before comparing), thereby avoiding reliance on any specific trial order.
Bonus Points for CP949
This is an interesting heuristic adjustment. The logic is: "If the original detector believes it's CP949 and it passes the round-trip test (score > 0), we give it a slight preference, respecting the original detector's judgment." This helps maintain stability when both encodings are genuinely valid (an extremely rare occurrence). While the number 3 is an empirical value, it causes no harm since character-count differences are typically large.
Dynamic Threshold
This dynamic threshold is ingeniously designed. For very short text, it requires at least 2 matching characters; for longer text, it demands more matches, but caps the requirement at 8. This prevents incorrect judgments in long texts based solely on one or two accidental matches.
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods