summaryrefslogtreecommitdiff
path: root/gitlab/base.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-01-09 00:53:12 -0800
committerJohn L. Villalovos <john@sodarock.com>2022-01-09 00:53:12 -0800
commit99e1f8bad3e52ca6fb2dc6b876a262c6fee39e41 (patch)
tree6a11bdaf3e49a3dec844255d74a860798e8acc68 /gitlab/base.py
parentac812727c26c9bde4ee5c1115029f2ff4ab1964b (diff)
downloadgitlab-jlvillal/encoded_id_alt.tar.gz
fix: use url-encoded ID in all paths ALTERNATE METHODjlvillal/encoded_id_alt
An alternative to https://github.com/python-gitlab/python-gitlab/pull/1819 Make sure all usage of the ID in the URL path is encoded. Normally it isn't an issue as most IDs are integers or strings which don't contain a slash ('/'). But when the ID is a string with a slash character it will break things. Add a test case that shows this fixes wikis issue with subpages which use the slash character. Closes: #1079
Diffstat (limited to 'gitlab/base.py')
-rw-r--r--gitlab/base.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/gitlab/base.py b/gitlab/base.py
index 50f09c5..cec710c 100644
--- a/gitlab/base.py
+++ b/gitlab/base.py
@@ -209,6 +209,15 @@ class RESTObject(object):
return getattr(self, self._id_attr)
@property
+ def encoded_id(self) -> Any:
+ """Ensure that the ID is url-encoded so that it can be safely used in a URL
+ path"""
+ obj_id = self.get_id()
+ if isinstance(obj_id, str):
+ obj_id = gitlab.utils.EncodedId(obj_id)
+ return obj_id
+
+ @property
def attributes(self) -> Dict[str, Any]:
d = self.__dict__["_updated_attrs"].copy()
d.update(self.__dict__["_attrs"])