summaryrefslogtreecommitdiff
path: root/gitlab/utils.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-01-09 22:11:47 -0800
committerJohn L. Villalovos <john@sodarock.com>2022-01-13 10:31:24 -0800
commit12435d74364ca881373d690eab89d2e2baa62a49 (patch)
tree7976389d86a50666458d3f45d2ca64fb6deb0e50 /gitlab/utils.py
parent824151ce9238f97118ec21aa8b3267cc7a2cd649 (diff)
downloadgitlab-12435d74364ca881373d690eab89d2e2baa62a49.tar.gz
fix: use url-encoded ID in all paths
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/utils.py')
-rw-r--r--gitlab/utils.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py
index 1f29104..7914521 100644
--- a/gitlab/utils.py
+++ b/gitlab/utils.py
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib.parse
-from typing import Any, Callable, Dict, Optional
+from typing import Any, Callable, Dict, Optional, overload, Union
import requests
@@ -56,7 +56,17 @@ def copy_dict(dest: Dict[str, Any], src: Dict[str, Any]) -> None:
dest[k] = v
+@overload
+def _url_encode(id: int) -> int:
+ ...
+
+
+@overload
def _url_encode(id: str) -> str:
+ ...
+
+
+def _url_encode(id: Union[int, str]) -> Union[int, str]:
"""Encode/quote the characters in the string so that they can be used in a path.
Reference to documentation on why this is necessary.
@@ -74,6 +84,8 @@ def _url_encode(id: str) -> str:
parameters.
"""
+ if isinstance(id, int):
+ return id
return urllib.parse.quote(id, safe="")