From 611ac76a2ea518f85882b2188c1888db1a94c3f8 Mon Sep 17 00:00:00 2001 From: cloxl Date: Tue, 13 Jan 2026 18:04:55 +0800 Subject: [PATCH 1/2] fix(client): encode non-ASCII characters in GET params while preserving commas --- src/xhshow/client.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/xhshow/client.py b/src/xhshow/client.py index 139881f..303c9bf 100644 --- a/src/xhshow/client.py +++ b/src/xhshow/client.py @@ -1,6 +1,7 @@ import hashlib import json import time +import urllib.parse from typing import Any, Literal from .config import CryptoConfig @@ -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): + 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: From 1bb031133f200fa559e7abb02c65cddee5edcb97 Mon Sep 17 00:00:00 2001 From: cloxl Date: Tue, 13 Jan 2026 18:06:39 +0800 Subject: [PATCH 2/2] format --- src/xhshow/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xhshow/client.py b/src/xhshow/client.py index 303c9bf..a44d1c0 100644 --- a/src/xhshow/client.py +++ b/src/xhshow/client.py @@ -50,13 +50,13 @@ def _build_content_string(self, method: str, uri: str, payload: dict[str, Any] | params = [] for key, value in payload.items(): if isinstance(value, list | tuple): - value_str = ','.join(str(v) for v in value) + value_str = ",".join(str(v) for v in value) elif value is not None: value_str = str(value) else: - value_str = '' + value_str = "" - encoded_value = urllib.parse.quote(value_str, safe=',') + encoded_value = urllib.parse.quote(value_str, safe=",") params.append(f"{key}={encoded_value}") return f"{uri}?{'&'.join(params)}"