Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/xhshow/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import json
import time
import urllib.parse
from typing import Any, Literal

from .config import CryptoConfig
Expand Down Expand Up @@ -46,12 +47,18 @@ def _build_content_string(self, method: str, uri: str, payload: dict[str, Any] |
if not payload:
return uri
else:
# XHS signature algorithm requires only '=' to be encoded as '%3D',
# other characters (including ',') should remain unencoded
params = [
f"{key}={(','.join(str(v) for v in value) if isinstance(value, list | tuple) else (str(value) if value is not None else '')).replace('=', '%3D')}" # noqa: E501
for key, value in payload.items()
]
params = []
for key, value in payload.items():
if isinstance(value, list | tuple):
Copy link

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.UnionTypeisinstance 不接受该类型,并会在运行时抛出 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.

value_str = ",".join(str(v) for v in value)
elif value is not None:
value_str = str(value)
else:
value_str = ""

encoded_value = urllib.parse.quote(value_str, safe=",")
params.append(f"{key}={encoded_value}")

return f"{uri}?{'&'.join(params)}"

def _generate_d_value(self, content: str) -> str:
Expand Down