diff options
author | John L. Villalovos <john@sodarock.com> | 2022-01-08 13:58:04 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2022-01-08 13:58:04 -0800 |
commit | 8c17afafcc7d9d2a8fecb53b853c2b4f004c4121 (patch) | |
tree | 10193bc1178dab265df9cd8fa31cff278e6ad909 /gitlab/v4/objects/files.py | |
parent | d45b59e800a14460a1ecdad2d750e42aa99bb96e (diff) | |
download | gitlab-jlvillal/remove_replace.tar.gz |
chore: remove custom URL encodingjlvillal/remove_replace
We were using `str.replace()` calls to take care of URL encoding
issues.
Switch them to use our `utils.clean_str_id` which itself uses
`urllib.parse.quote()`
Closes: #1356
Diffstat (limited to 'gitlab/v4/objects/files.py')
-rw-r--r-- | gitlab/v4/objects/files.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index c3a8ec8..69004f8 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -56,7 +56,7 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): """ self.branch = branch self.commit_message = commit_message - self.file_path = self.file_path.replace("/", "%2F") + self.file_path = utils.clean_str_id(self.file_path) super(ProjectFile, self).save(**kwargs) @exc.on_http_error(exc.GitlabDeleteError) @@ -76,7 +76,7 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - file_path = self.get_id().replace("/", "%2F") + file_path = utils.clean_str_id(self.get_id()) self.manager.delete(file_path, branch, commit_message, **kwargs) @@ -144,7 +144,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa assert data is not None self._check_missing_create_attrs(data) new_data = data.copy() - file_path = new_data.pop("file_path").replace("/", "%2F") + file_path = utils.clean_str_id(new_data.pop("file_path")) path = f"{self.path}/{file_path}" server_data = self.gitlab.http_post(path, post_data=new_data, **kwargs) if TYPE_CHECKING: @@ -173,7 +173,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa """ new_data = new_data or {} data = new_data.copy() - file_path = file_path.replace("/", "%2F") + file_path = utils.clean_str_id(file_path) data["file_path"] = file_path path = f"{self.path}/{file_path}" self._check_missing_update_attrs(data) @@ -203,7 +203,8 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - path = f"{self.path}/{file_path.replace('/', '%2F')}" + file_path = utils.clean_str_id(file_path) + path = f"{self.path}/{file_path}" data = {"branch": branch, "commit_message": commit_message} self.gitlab.http_delete(path, query_data=data, **kwargs) @@ -238,7 +239,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa Returns: The file content """ - file_path = file_path.replace("/", "%2F").replace(".", "%2E") + file_path = utils.clean_str_id(file_path) path = f"{self.path}/{file_path}/raw" query_data = {"ref": ref} result = self.gitlab.http_get( @@ -265,7 +266,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa Returns: A list of commits/lines matching the file """ - file_path = file_path.replace("/", "%2F").replace(".", "%2E") + file_path = utils.clean_str_id(file_path) path = f"{self.path}/{file_path}/blame" query_data = {"ref": ref} result = self.gitlab.http_list(path, query_data, **kwargs) |