Skip to content

Commit cf6c0ba

Browse files
dmcppcheckclaude
andcommitted
donate-cpu-server-rest: use the undecoded path in the "packages.txt" link
request.url.path is decoded and the name pages decode the path again ('+' is a space). For a name with a '+', e.g. operator+(), the link became /check_library-operator+()?pkgs=1 which gave the name "operator ()" and an empty list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9b89bab commit cf6c0ba

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎test/tools/donate_cpu_server_rest_test.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ def test_html_name_pages(client):
256256
assert 'please configure it' in client.get('/unknown_macro-FOO').text
257257

258258

259+
def test_html_name_pages_packages_link(client):
260+
# the "packages.txt" link must give the same name as the page
261+
info = INFO + 'aaa/x.c:5:1: information: --check-library: There is no matching configuration for function operator+() [checkLibraryFunction]\n'
262+
assert client.post('/api/v1/info', content=info).status_code == 201
263+
for path in ['/check_library-operator%2B%28%29', '/check_library-unsigned+int']:
264+
page = client.get(path).text
265+
assert 'href="{}?pkgs=1"'.format(path) in page, path
266+
assert client.get(path + '?pkgs=1').text == PKG_A + '\n', path
267+
268+
259269
def test_safe_path(tmp_path):
260270
directory = str(tmp_path)
261271
assert server.safe_path(directory, 'pkg') == str(tmp_path / 'pkg')

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,11 @@ def packages_text(rows: List[Dict[str, Any]]) -> PlainTextResponse:
982982
def with_query(request: Request, **params: str) -> str:
983983
query = dict(request.query_params)
984984
query.update(params)
985-
return request.url.path + '?' + urllib.parse.urlencode(query)
985+
# use the undecoded path: request.url.path is decoded, and the name pages decode the path
986+
# 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)
986990

987991

988992
OVERVIEW_GROUPS = [

0 commit comments

Comments
 (0)