GeezerVison is showing github.com — fix: stop encoding '.' to '%2E' · python-gitlab/python-gitlab@daa2e65
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: gitlab/client.py +10-16Lines changed: 10 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -593,24 +593,18 @@ def http_request( | 593 | 593 | json, data, content_type = self._prepare_send_data(files, post_data, raw) | 594 | 594 | opts["headers"]["Content-type"] = content_type | 595 | 595 |
| 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 | | - | 611 | 596 | cur_retries = 0 | 612 | 597 | 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 | + verify=verify, | | 605 | + stream=streamed, | | 606 | + **opts, | | 607 | + ) | 614 | 608 |
| 615 | 609 | self._check_redirects(result) | 616 | 610 |
| |
Collapse file Copy file name to clipboardExpand all lines: gitlab/utils.py +1-7Lines changed: 1 addition & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | 17 |
| 18 | 18 | from typing import Any, Callable, Dict, Optional | 19 | | -from urllib.parse import quote, urlparse | | 19 | +from urllib.parse import quote | 20 | 20 |
| 21 | 21 | import requests | 22 | 22 |
| @@ -60,11 +60,5 @@ def clean_str_id(id: str) -> str: | 60 | 60 | return quote(id, safe="") | 61 | 61 |
| 62 | 62 |
| 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 | | - | 69 | 63 | def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]: | 70 | 64 | return {k: v for k, v in data.items() if v is not None} |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/objects/test_packages.py +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | GitLab API: https://docs.gitlab.com/ce/api/packages.html | 3 | 3 | """ | 4 | 4 | import re | 5 | | -from urllib.parse import quote_plus | 6 | 5 |
| 7 | 6 | import pytest | 8 | 7 | import responses | | 109 | 108 | file_name = "hello.tar.gz" | 110 | 109 | file_content = "package content" | 111 | 110 | 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, | 116 | 114 | ) | 117 | 115 |
| 118 | 116 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/objects/test_releases.py +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | from gitlab.v4.objects import ProjectReleaseLink | 12 | 12 |
| 13 | 13 | tag_name = "v1.0.0" | 14 | | -encoded_tag_name = "v1%2E0%2E0" | 15 | 14 | release_name = "demo-release" | 16 | 15 | release_description = "my-rel-desc" | 17 | 16 | released_at = "2019-03-15T08:00:00Z" | 18 | 17 | link_name = "hello-world" | 19 | 18 | 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" | 21 | 20 | new_link_type = "package" | 22 | 21 | link_content = { | 23 | 22 | "id": 2, | | 37 | 36 | "released_at": released_at, | 38 | 37 | } | 39 | 38 |
| 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}") | 43 | 40 | 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" | 45 | 42 | ) | 46 | 43 | 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" | 48 | 45 | ) | 49 | 46 |
| 50 | 47 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/objects/test_repositories.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,8 +29,7 @@ def resp_get_repository_file(): | 29 | 29 | "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", | 30 | 30 | } | 31 | 31 |
| 32 | | - # requests also encodes `.` | 33 | | - encoded_path = quote(file_path, safe="").replace(".", "%2E") | | 32 | + encoded_path = quote(file_path, safe="") | 34 | 33 |
| 35 | 34 | with responses.RequestsMock() as rsps: | 36 | 35 | rsps.add( | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/test_utils.py -10Lines changed: 0 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,13 +30,3 @@ def test_clean_str_id(): | 30 | 30 | src = "foo%bar/baz/" | 31 | 31 | dest = "foo%25bar%2Fbaz%2F" | 32 | 32 | 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) |
|