FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: stop encoding '.' to '%2E' by JohnVillalovos · Pull Request #1766 · python-gitlab/python-gitlab · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (6) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 11 additions & 16 deletions gitlab/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -593,24 +593,19 @@ def http_request(
json, data, content_type = self._prepare_send_data(files, post_data, raw)
opts["headers"]["Content-type"] = content_type

# Requests assumes that `.` should not be encoded as %2E and will make
# changes to urls using this encoding. Using a prepped request we can
# get the desired behavior.
# The Requests behavior is right but it seems that web servers don't
# always agree with this decision (this is the case with a default
# gitlab installation)
req = requests.Request(verb, url, json=json, data=data, params=params, **opts)
prepped = self.session.prepare_request(req)
if TYPE_CHECKING:
assert prepped.url is not None
prepped.url = utils.sanitized_url(prepped.url)
settings = self.session.merge_environment_settings(
prepped.url, {}, streamed, verify, None
)

cur_retries = 0
while True:
result = self.session.send(prepped, timeout=timeout, **settings)
result = self.session.request(
method=verb,
url=url,
json=json,
data=data,
params=params,
timeout=timeout,
verify=verify,
stream=streamed,
**opts,
)

self._check_redirects(result)

Expand Down
8 changes: 1 addition & 7 deletions gitlab/utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Any, Callable, Dict, Optional
from urllib.parse import quote, urlparse
from urllib.parse import quote

import requests

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


def sanitized_url(url: str) -> str:
parsed = urlparse(url)
new_path = parsed.path.replace(".", "%2E")
return parsed._replace(path=new_path).geturl()


def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]:
return {k: v for k, v in data.items() if v is not None}
8 changes: 3 additions & 5 deletions tests/unit/objects/test_packages.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
GitLab API: https://docs.gitlab.com/ce/api/packages.html
"""
import re
from urllib.parse import quote_plus

import pytest
import responses
Expand Down Expand Up @@ -109,10 +108,9 @@
file_name = "hello.tar.gz"
file_content = "package content"
package_url = "http://localhost/api/v4/projects/1/packages/generic/{}/{}/{}".format(
# https://datatracker.ietf.org/doc/html/rfc3986.html#section-2.3 :(
quote_plus(package_name).replace(".", "%2E"),
quote_plus(package_version).replace(".", "%2E"),
quote_plus(file_name).replace(".", "%2E"),
package_name,
package_version,
file_name,
)


Expand Down
11 changes: 4 additions & 7 deletions tests/unit/objects/test_releases.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
from gitlab.v4.objects import ProjectReleaseLink

tag_name = "v1.0.0"
encoded_tag_name = "v1%2E0%2E0"
release_name = "demo-release"
release_description = "my-rel-desc"
released_at = "2019-03-15T08:00:00Z"
link_name = "hello-world"
link_url = "https://gitlab.example.com/group/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64"
direct_url = f"https://gitlab.example.com/group/hello/-/releases/{encoded_tag_name}/downloads/hello-world"
direct_url = f"https://gitlab.example.com/group/hello/-/releases/{tag_name}/downloads/hello-world"
new_link_type = "package"
link_content = {
"id": 2,
Expand All @@ -37,14 +36,12 @@
"released_at": released_at,
}

release_url = re.compile(
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}"
)
release_url = re.compile(rf"http://localhost/api/v4/projects/1/releases/{tag_name}")
links_url = re.compile(
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links"
rf"http://localhost/api/v4/projects/1/releases/{tag_name}/assets/links"
)
link_id_url = re.compile(
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links/1"
rf"http://localhost/api/v4/projects/1/releases/{tag_name}/assets/links/1"
)


Expand Down
3 changes: 1 addition & 2 deletions tests/unit/objects/test_repositories.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def resp_get_repository_file():
"last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
}

# requests also encodes `.`
encoded_path = quote(file_path, safe="").replace(".", "%2E")
encoded_path = quote(file_path, safe="")

with responses.RequestsMock() as rsps:
rsps.add(
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/test_utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,3 @@ def test_clean_str_id():
src = "foo%bar/baz/"
dest = "foo%25bar%2Fbaz%2F"
assert dest == utils.clean_str_id(src)


def test_sanitized_url():
src = "http://localhost/foo/bar"
dest = "http://localhost/foo/bar"
assert dest == utils.sanitized_url(src)

src = "http://localhost/foo.bar.baz"
dest = "http://localhost/foo%2Ebar%2Ebaz"
assert dest == utils.sanitized_url(src)

Back | FazBrowse Home | New Git URL