summaryrefslogtreecommitdiff
path: root/gitlab/utils.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-01-08 16:10:27 -0800
committerJohn L. Villalovos <john@sodarock.com>2022-01-08 16:13:59 -0800
commit3d49e5e6a2bf1c9a883497acb73d7ce7115b804d (patch)
treed16d4dcdec97ea3afb09ef7403d784e288ede49f /gitlab/utils.py
parent0dba899c20dda3a9789992a1186cfd718e5b588f (diff)
downloadgitlab-3d49e5e6a2bf1c9a883497acb73d7ce7115b804d.tar.gz
fix: remove custom URL encoding
We were using `str.replace()` calls to take care of URL encoding issues. Switch them to use our `utils._url_encode()` function which itself uses `urllib.parse.quote()` Closes: #1356
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]: