Skip to content

Commit eef8059

Browse files
authored
Merge pull request #1766 from python-gitlab/jlvillal/leave_dot
fix: stop encoding '.' to '%2E'
2 parents 182ab92 + 702e41d commit eef8059

File tree

6 files changed

+20
-47
lines changed

6 files changed

+20
-47
lines changed

gitlab/client.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -593,24 +593,19 @@ def http_request(
593593
json, data, content_type = self._prepare_send_data(files, post_data, raw)
594594
opts["headers"]["Content-type"] = content_type
595595

596-
# Requests assumes that `.` should not be encoded as %2E and will make
597-
# changes to urls using this encoding. Using a prepped request we can
598-
# get the desired behavior.
599-
# The Requests behavior is right but it seems that web servers don't
600-
# always agree with this decision (this is the case with a default
601-
# gitlab installation)
602-
req = requests.Request(verb, url, json=json, data=data, params=params, **opts)
603-
prepped = self.session.prepare_request(req)
604-
if TYPE_CHECKING:
605-
assert prepped.url is not None
606-
prepped.url = utils.sanitized_url(prepped.url)
607-
settings = self.session.merge_environment_settings(
608-
prepped.url, {}, streamed, verify, None
609-
)
610-
611596
cur_retries = 0
612597
while True:
613-
result = self.session.send(prepped, timeout=timeout, **settings)
598+
result = self.session.request(
599+
method=verb,
600+
url=url,
601+
json=json,
602+
data=data,
603+
params=params,
604+
timeout=timeout,
605+
verify=verify,
606+
stream=streamed,
607+
**opts,
608+
)
614609

615610
self._check_redirects(result)
616611

gitlab/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
from typing import Any, Callable, Dict, Optional
19-
from urllib.parse import quote, urlparse
19+
from urllib.parse import quote
2020

2121
import requests
2222

@@ -60,11 +60,5 @@ def clean_str_id(id: str) -> str:
6060
return quote(id, safe="")
6161

6262

63-
def sanitized_url(url: str) -> str:
64-
parsed = urlparse(url)
65-
new_path = parsed.path.replace(".", "%2E")
66-
return parsed._replace(path=new_path).geturl()
67-
68-
6963
def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]:
7064
return {k: v for k, v in data.items() if v is not None}

tests/unit/objects/test_packages.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
GitLab API: https://docs.gitlab.com/ce/api/packages.html
33
"""
44
import re
5-
from urllib.parse import quote_plus
65

76
import pytest
87
import responses
@@ -109,10 +108,9 @@
109108
file_name = "hello.tar.gz"
110109
file_content = "package content"
111110
package_url = "http://localhost/api/v4/projects/1/packages/generic/{}/{}/{}".format(
112-
# https://datatracker.ietf.org/doc/html/rfc3986.html#section-2.3 :(
113-
quote_plus(package_name).replace(".", "%2E"),
114-
quote_plus(package_version).replace(".", "%2E"),
115-
quote_plus(file_name).replace(".", "%2E"),
111+
package_name,
112+
package_version,
113+
file_name,
116114
)
117115

118116

tests/unit/objects/test_releases.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
from gitlab.v4.objects import ProjectReleaseLink
1212

1313
tag_name = "v1.0.0"
14-
encoded_tag_name = "v1%2E0%2E0"
1514
release_name = "demo-release"
1615
release_description = "my-rel-desc"
1716
released_at = "2019-03-15T08:00:00Z"
1817
link_name = "hello-world"
1918
link_url = "https://gitlab.example.com/group/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64"
20-
direct_url = f"https://gitlab.example.com/group/hello/-/releases/{encoded_tag_name}/downloads/hello-world"
19+
direct_url = f"https://gitlab.example.com/group/hello/-/releases/{tag_name}/downloads/hello-world"
2120
new_link_type = "package"
2221
link_content = {
2322
"id": 2,
@@ -37,14 +36,12 @@
3736
"released_at": released_at,
3837
}
3938

40-
release_url = re.compile(
41-
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}"
42-
)
39+
release_url = re.compile(rf"http://localhost/api/v4/projects/1/releases/{tag_name}")
4340
links_url = re.compile(
44-
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links"
41+
rf"http://localhost/api/v4/projects/1/releases/{tag_name}/assets/links"
4542
)
4643
link_id_url = re.compile(
47-
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links/1"
44+
rf"http://localhost/api/v4/projects/1/releases/{tag_name}/assets/links/1"
4845
)
4946

5047

tests/unit/objects/test_repositories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def resp_get_repository_file():
2929
"last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
3030
}
3131

32-
# requests also encodes `.`
33-
encoded_path = quote(file_path, safe="").replace(".", "%2E")
32+
encoded_path = quote(file_path, safe="")
3433

3534
with responses.RequestsMock() as rsps:
3635
rsps.add(

tests/unit/test_utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,3 @@ def test_clean_str_id():
3030
src = "foo%bar/baz/"
3131
dest = "foo%25bar%2Fbaz%2F"
3232
assert dest == utils.clean_str_id(src)
33-
34-
35-
def test_sanitized_url():
36-
src = "http://localhost/foo/bar"
37-
dest = "http://localhost/foo/bar"
38-
assert dest == utils.sanitized_url(src)
39-
40-
src = "http://localhost/foo.bar.baz"
41-
dest = "http://localhost/foo%2Ebar%2Ebaz"
42-
assert dest == utils.sanitized_url(src)

0 commit comments

Comments
 (0)