Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd263f57

Browse files
authored
Merge pull request#2219 from python-gitlab/fix/no-duplicate-params
fix(client): ensure encoded query params are never duplicated
2 parents2ebfc70 +1398426 commitd263f57

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

‎gitlab/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
importre
2121
importtime
2222
fromtypingimportAny,cast,Dict,List,Optional,Tuple,TYPE_CHECKING,Union
23+
fromurllibimportparse
2324

2425
importrequests
2526
importrequests.utils
@@ -677,11 +678,15 @@ def http_request(
677678
GitlabHttpError: When the return code is not 2xx
678679
"""
679680
query_data=query_dataor {}
680-
url=self._build_url(path)
681+
raw_url=self._build_url(path)
681682

682-
params:Dict[str,Any]= {}
683+
# parse user-provided URL params to ensure we don't add our own duplicates
684+
parsed=parse.urlparse(raw_url)
685+
params=parse.parse_qs(parsed.query)
683686
utils.copy_dict(src=query_data,dest=params)
684687

688+
url=raw_url.replace(parsed.query,"").strip("?")
689+
685690
# Deal with kwargs: by default a user uses kwargs to send data to the
686691
# gitlab server, but this generates problems (python keyword conflicts
687692
# and python-gitlab/gitlab conflicts).

‎tests/unit/test_gitlab_http_methods.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ def test_http_request(gl):
3636
assertresponses.assert_call_count(url,1)isTrue
3737

3838

39+
@responses.activate
40+
deftest_http_request_with_url_encoded_kwargs_does_not_duplicate_params(gl):
41+
url="http://localhost/api/v4/projects?topics%5B%5D=python"
42+
responses.add(
43+
method=responses.GET,
44+
url=url,
45+
json=[{"name":"project1"}],
46+
status=200,
47+
match=[responses.matchers.query_param_matcher({"topics[]":"python"})],
48+
)
49+
50+
kwargs= {"topics[]":"python"}
51+
http_r=gl.http_request("get","/projects?topics%5B%5D=python",**kwargs)
52+
http_r.json()
53+
asserthttp_r.status_code==200
54+
assertresponses.assert_call_count(url,1)
55+
56+
3957
@responses.activate
4058
deftest_http_request_404(gl):
4159
url="http://localhost/api/v4/not_there"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp