Skip to content

Commit f33f430

Browse files
dmcppcheckclaude
andcommitted
donate-cpu-server-rest: strip the query string from raw_path
Older Starlette TestClient versions (0.27, used with Python 3.7) put the query string in scope['raw_path'], so '?pkgs=1' became part of the name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cf6c0ba commit f33f430

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎tools/donate-cpu-server-rest.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,14 +979,20 @@ def packages_text(rows: List[Dict[str, Any]]) -> PlainTextResponse:
979979
return PlainTextResponse(''.join(r['url'] + '\n' for r in rows if r.get('url')))
980980

981981

982+
def raw_path(request: Request) -> str:
983+
"""The undecoded path, without the query string (some ASGI servers include it in 'raw_path')."""
984+
raw = request.scope.get('raw_path')
985+
if not raw:
986+
return urllib.parse.quote(request.url.path)
987+
return raw.decode('latin-1').split('?', 1)[0]
988+
989+
982990
def with_query(request: Request, **params: str) -> str:
983991
query = dict(request.query_params)
984992
query.update(params)
985993
# use the undecoded path: request.url.path is decoded, and the name pages decode the path
986994
# again ('+' is a space), so a decoded '%2B' would become a space
987-
raw = request.scope.get('raw_path')
988-
path = raw.decode('latin-1') if raw else urllib.parse.quote(request.url.path)
989-
return path + '?' + urllib.parse.urlencode(query)
995+
return raw_path(request) + '?' + urllib.parse.urlencode(query)
990996

991997

992998
OVERVIEW_GROUPS = [
@@ -1099,8 +1105,7 @@ def _check_versions(data: str) -> None:
10991105
def _raw_suffix(request: Request, prefix: str) -> str:
11001106
"""The part of the undecoded path after 'prefix', decoded like donate-cpu-server.py does it
11011107
('+' is a space), so that links from the old server keep working."""
1102-
raw = request.scope.get('raw_path') or request.url.path.encode()
1103-
return urllib.parse.unquote_plus(raw.decode('latin-1')[len(prefix):])
1108+
return urllib.parse.unquote_plus(raw_path(request)[len(prefix):])
11041109

11051110

11061111
def create_app(work_path: str, rescan_interval: float = DEFAULT_RESCAN_INTERVAL) -> FastAPI:

0 commit comments

Comments
 (0)