Skip to content

Commit 37af229

Browse files
authored
Merge pull request #1418 from python-gitlab/fix/urlencode-file-paths
fix(files): do not url-encode filepaths twice
2 parents e37de18 + 8e25cec commit 37af229

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

gitlab/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
__email__ = "gauvainpocentek@gmail.com"
44
__license__ = "LGPL3"
55
__title__ = "python-gitlab"
6-
__version__ = "2.7.0"
6+
__version__ = "2.7.1"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ee/api/repositories.html
4+
https://docs.gitlab.com/ee/api/repository_files.html
5+
"""
6+
from urllib.parse import quote
7+
8+
import pytest
9+
import responses
10+
11+
from gitlab.v4.objects import ProjectFile
12+
13+
file_path = "app/models/key.rb"
14+
ref = "main"
15+
16+
17+
@pytest.fixture
18+
def resp_get_repository_file():
19+
file_response = {
20+
"file_name": "key.rb",
21+
"file_path": file_path,
22+
"size": 1476,
23+
"encoding": "base64",
24+
"content": "IyA9PSBTY2hlbWEgSW5mb3...",
25+
"content_sha256": "4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481",
26+
"ref": ref,
27+
"blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83",
28+
"commit_id": "d5a3ff139356ce33e37e73add446f16869741b50",
29+
"last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
30+
}
31+
32+
# requests also encodes `.`
33+
encoded_path = quote(file_path, safe="").replace(".", "%2E")
34+
35+
with responses.RequestsMock() as rsps:
36+
rsps.add(
37+
method=responses.GET,
38+
url=f"http://localhost/api/v4/projects/1/repository/files/{encoded_path}",
39+
json=file_response,
40+
content_type="application/json",
41+
status=200,
42+
)
43+
yield rsps
44+
45+
46+
def test_get_repository_file(project, resp_get_repository_file):
47+
file = project.files.get(file_path, ref=ref)
48+
assert isinstance(file, ProjectFile)
49+
assert file.file_path == file_path

gitlab/v4/objects/files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def get(self, file_path, ref, **kwargs):
9494
Returns:
9595
object: The generated RESTObject
9696
"""
97-
file_path = file_path.replace("/", "%2F")
9897
return GetMixin.get(self, file_path, ref=ref, **kwargs)
9998

10099
@cli.register_custom_action(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy