-
Notifications
You must be signed in to change notification settings - Fork 175
fix(client): encode non-ASCII characters in GET params while preservi… #85
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
Conversation
评审者指南(在小型 PR 上折叠)评审者指南重构 GET 查询参数的构建逻辑,使用标准的 URL 百分号编码(允许逗号)来处理参数值,替换之前仅对 客户端中 GET 参数编码的流程图flowchart TD
Start["_build_content_string called"] --> CheckMethod{"method == 'GET'?"}
CheckMethod -- "No" --> ReturnURI["Return uri unchanged"]
CheckMethod -- "Yes" --> CheckPayload{"payload is empty?"}
CheckPayload -- "Yes" --> ReturnURIGet["Return uri unchanged"]
CheckPayload -- "No" --> InitParams["Initialize empty params list"]
InitParams --> LoopItems["For each key, value in payload.items()"]
LoopItems --> CheckListTuple{"value is list or tuple?"}
CheckListTuple -- "Yes" --> JoinList["value_str = comma-joined string of items"]
CheckListTuple -- "No" --> CheckNone{"value is not None?"}
CheckNone -- "Yes" --> ToString["value_str = str(value)"]
CheckNone -- "No" --> EmptyStr["value_str = empty string"]
JoinList --> EncodeValue
ToString --> EncodeValue
EmptyStr --> EncodeValue
EncodeValue["encoded_value = urllib.parse.quote(value_str, safe=',' )"] --> AppendParam["Append f'key=encoded_value' to params list"]
AppendParam --> NextItem{"More items in payload?"}
NextItem -- "Yes" --> LoopItems
NextItem -- "No" --> BuildQuery["Return f'{uri}?{ '&'.join(params) }'"]
文件级变更
与关联 issue 的对照评估
使用技巧与命令与 Sourcery 互动
自定义你的体验打开你的 dashboard 可以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors GET query parameter construction to use standard URL percent-encoding for values (while allowing commas), replacing the prior custom '='-only encoding, to correctly handle non-ASCII characters in client request signing. Flow diagram for GET parameter encoding in clientflowchart TD
Start["_build_content_string called"] --> CheckMethod{"method == 'GET'?"}
CheckMethod -- "No" --> ReturnURI["Return uri unchanged"]
CheckMethod -- "Yes" --> CheckPayload{"payload is empty?"}
CheckPayload -- "Yes" --> ReturnURIGet["Return uri unchanged"]
CheckPayload -- "No" --> InitParams["Initialize empty params list"]
InitParams --> LoopItems["For each key, value in payload.items()"]
LoopItems --> CheckListTuple{"value is list or tuple?"}
CheckListTuple -- "Yes" --> JoinList["value_str = comma-joined string of items"]
CheckListTuple -- "No" --> CheckNone{"value is not None?"}
CheckNone -- "Yes" --> ToString["value_str = str(value)"]
CheckNone -- "No" --> EmptyStr["value_str = empty string"]
JoinList --> EncodeValue
ToString --> EncodeValue
EmptyStr --> EncodeValue
EncodeValue["encoded_value = urllib.parse.quote(value_str, safe=',' )"] --> AppendParam["Append f'key=encoded_value' to params list"]
AppendParam --> NextItem{"More items in payload?"}
NextItem -- "Yes" --> LoopItems
NextItem -- "No" --> BuildQuery["Return f'{uri}?{ '&'.join(params) }'"]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - 我发现了 1 个问题,并提供了一些整体性的反馈:
- 建议像对参数值一样,对参数键也应用相同的
urllib.parse.quote编码,这样可以让键中出现的非 ASCII 或保留字符与值的处理方式保持一致。 - 可以考虑将查询字符串的构造逻辑集中到一个小的辅助函数中,这样编码规则(例如
safe=',')只定义在一个地方,如果签名需求以后再次变化,也更便于审查和调整。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- Consider applying the same `urllib.parse.quote` encoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values.
- It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g., `safe=','`) are defined in one place and easier to audit or adjust if the signature requirements change again.
## Individual Comments
### Comment 1
<location> `src/xhshow/client.py:52` </location>
<code_context>
- ]
+ params = []
+ for key, value in payload.items():
+ if isinstance(value, list | tuple):
+ value_str = ','.join(str(v) for v in value)
+ elif value is not None:
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `list | tuple` in `isinstance` is invalid at runtime; use a tuple of types instead.
`list | tuple` creates a `types.UnionType`, which `isinstance` does not accept and will raise `TypeError` at runtime. Use `isinstance(value, (list, tuple))` to preserve the intended behavior.
</issue_to_address>帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- Consider applying the same
urllib.parse.quoteencoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values. - It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g.,
safe=',') are defined in one place and easier to audit or adjust if the signature requirements change again.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider applying the same `urllib.parse.quote` encoding to the parameter keys as you do to the values so that non-ASCII or reserved characters in keys are handled consistently with values.
- It may be worth centralizing the query-string construction into a small helper function so that the encoding rules (e.g., `safe=','`) are defined in one place and easier to audit or adjust if the signature requirements change again.
## Individual Comments
### Comment 1
<location> `src/xhshow/client.py:52` </location>
<code_context>
- ]
+ params = []
+ for key, value in payload.items():
+ if isinstance(value, list | tuple):
+ value_str = ','.join(str(v) for v in value)
+ elif value is not None:
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `list | tuple` in `isinstance` is invalid at runtime; use a tuple of types instead.
`list | tuple` creates a `types.UnionType`, which `isinstance` does not accept and will raise `TypeError` at runtime. Use `isinstance(value, (list, tuple))` to preserve the intended behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| ] | ||
| params = [] | ||
| for key, value in payload.items(): | ||
| if isinstance(value, list | tuple): |
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.
issue (bug_risk): 在 isinstance 中使用 list | tuple 在运行时是无效的;请改用类型元组。
list | tuple 会创建一个 types.UnionType,isinstance 不接受该类型,并会在运行时抛出 TypeError。请使用 isinstance(value, (list, tuple)) 来保持原本的预期行为。
Original comment in English
issue (bug_risk): Using list | tuple in isinstance is invalid at runtime; use a tuple of types instead.
list | tuple creates a types.UnionType, which isinstance does not accept and will raise TypeError at runtime. Use isinstance(value, (list, tuple)) to preserve the intended behavior.
Fixes #84
Summary by Sourcery
错误修复:
'='。Original summary in English
Summary by Sourcery
Bug Fixes: