summaryrefslogtreecommitdiff
path: root/gitlab/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab/utils.py')
-rw-r--r--gitlab/utils.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py
index a1dcb45..1f29104 100644
--- a/gitlab/utils.py
+++ b/gitlab/utils.py
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import urllib.parse
from typing import Any, Callable, Dict, Optional
-from urllib.parse import quote
import requests
@@ -56,8 +56,25 @@ def copy_dict(dest: Dict[str, Any], src: Dict[str, Any]) -> None:
dest[k] = v
-def clean_str_id(id: str) -> str:
- return quote(id, safe="")
+def _url_encode(id: str) -> 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.
+
+ https://docs.gitlab.com/ee/api/index.html#namespaced-path-encoding
+
+ If using namespaced API requests, make sure that the NAMESPACE/PROJECT_PATH is
+ URL-encoded. For example, / is represented by %2F
+
+ https://docs.gitlab.com/ee/api/index.html#path-parameters
+
+ Path parameters that are required to be URL-encoded must be followed. If not, it
+ doesn’t match an API endpoint and responds with a 404. If there’s something in front
+ of the API (for example, Apache), ensure that it doesn’t decode the URL-encoded path
+ parameters.
+
+ """
+ return urllib.parse.quote(id, safe="")
def remove_none_from_dict(data: Dict[str, Any]) -> Dict[str, Any]: