@@ -56,7 +56,7 @@ def save( # type: ignore
56
56
"""
57
57
self .branch = branch
58
58
self .commit_message = commit_message
59
- self .file_path = self .file_path . replace ( "/" , "%2F" )
59
+ self .file_path = utils . _url_encode ( self .file_path )
60
60
super (ProjectFile , self ).save (** kwargs )
61
61
62
62
@exc .on_http_error (exc .GitlabDeleteError )
@@ -76,7 +76,7 @@ def delete( # type: ignore
76
76
GitlabAuthenticationError: If authentication is not correct
77
77
GitlabDeleteError: If the server cannot perform the request
78
78
"""
79
- file_path = self .get_id (). replace ( "/" , "%2F" )
79
+ file_path = utils . _url_encode ( self .get_id ())
80
80
self .manager .delete (file_path , branch , commit_message , ** kwargs )
81
81
82
82
@@ -144,7 +144,7 @@ def create(
144
144
assert data is not None
145
145
self ._check_missing_create_attrs (data )
146
146
new_data = data .copy ()
147
- file_path = new_data .pop ("file_path" ). replace ( "/" , "%2F" )
147
+ file_path = utils . _url_encode ( new_data .pop ("file_path" ))
148
148
path = f"{ self .path } /{ file_path } "
149
149
server_data = self .gitlab .http_post (path , post_data = new_data , ** kwargs )
150
150
if TYPE_CHECKING :
@@ -173,7 +173,7 @@ def update( # type: ignore
173
173
"""
174
174
new_data = new_data or {}
175
175
data = new_data .copy ()
176
- file_path = file_path . replace ( "/" , "%2F" )
176
+ file_path = utils . _url_encode ( file_path )
177
177
data ["file_path" ] = file_path
178
178
path = f"{ self .path } /{ file_path } "
179
179
self ._check_missing_update_attrs (data )
@@ -203,7 +203,8 @@ def delete( # type: ignore
203
203
GitlabAuthenticationError: If authentication is not correct
204
204
GitlabDeleteError: If the server cannot perform the request
205
205
"""
206
- path = f"{ self .path } /{ file_path .replace ('/' , '%2F' )} "
206
+ file_path = utils ._url_encode (file_path )
207
+ path = f"{ self .path } /{ file_path } "
207
208
data = {"branch" : branch , "commit_message" : commit_message }
208
209
self .gitlab .http_delete (path , query_data = data , ** kwargs )
209
210
@@ -238,7 +239,7 @@ def raw(
238
239
Returns:
239
240
The file content
240
241
"""
241
- file_path = file_path . replace ( "/" , "%2F" ). replace ( "." , "%2E" )
242
+ file_path = utils . _url_encode ( file_path )
242
243
path = f"{ self .path } /{ file_path } /raw"
243
244
query_data = {"ref" : ref }
244
245
result = self .gitlab .http_get (
@@ -265,7 +266,7 @@ def blame(self, file_path: str, ref: str, **kwargs: Any) -> List[Dict[str, Any]]
265
266
Returns:
266
267
A list of commits/lines matching the file
267
268
"""
268
- file_path = file_path . replace ( "/" , "%2F" ). replace ( "." , "%2E" )
269
+ file_path = utils . _url_encode ( file_path )
269
270
path = f"{ self .path } /{ file_path } /blame"
270
271
query_data = {"ref" : ref }
271
272
result = self .gitlab .http_list (path , query_data , ** kwargs )
0 commit comments