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

Commit8e25cec

Browse files
committed
fix(files): do not url-encode file paths twice
1 parente37de18 commit8e25cec

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+
fromurllib.parseimportquote
7+
8+
importpytest
9+
importresponses
10+
11+
fromgitlab.v4.objectsimportProjectFile
12+
13+
file_path="app/models/key.rb"
14+
ref="main"
15+
16+
17+
@pytest.fixture
18+
defresp_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+
withresponses.RequestsMock()asrsps:
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+
yieldrsps
44+
45+
46+
deftest_get_repository_file(project,resp_get_repository_file):
47+
file=project.files.get(file_path,ref=ref)
48+
assertisinstance(file,ProjectFile)
49+
assertfile.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
returnGetMixin.get(self,file_path,ref=ref,**kwargs)
9998

10099
@cli.register_custom_action(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp