Skip to content

Commit 48fc907

Browse files
authored
Merge pull request #1336 from em-/fix/quote-everything
fix: handle tags like debian/2%2.6-21 as identifiers
2 parents 63ecd2e + b4dac5c commit 48fc907

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

gitlab/tests/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def test_clean_str_id():
2727
dest = "foo%23bar%2Fbaz%2F"
2828
assert dest == utils.clean_str_id(src)
2929

30+
src = "foo%bar/baz/"
31+
dest = "foo%25bar%2Fbaz%2F"
32+
assert dest == utils.clean_str_id(src)
33+
3034

3135
def test_sanitized_url():
3236
src = "http://localhost/foo/bar"
@@ -48,6 +52,10 @@ def test_sanitize_parameters_slash():
4852
assert "foo%2Fbar" == utils.sanitize_parameters("foo/bar")
4953

5054

55+
def test_sanitize_parameters_slash_and_percent():
56+
assert "foo%2Fbar%25quuz" == utils.sanitize_parameters("foo/bar%quuz")
57+
58+
5159
def test_sanitize_parameters_dict():
5260
source = {"url": "foo/bar", "id": 1}
5361
expected = {"url": "foo%2Fbar", "id": 1}

gitlab/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
from typing import Any, Callable, Dict, Optional
19-
from urllib.parse import urlparse
19+
from urllib.parse import quote, urlparse
2020

2121
import requests
2222

@@ -57,14 +57,14 @@ def copy_dict(dest: Dict[str, Any], src: Dict[str, Any]) -> None:
5757

5858

5959
def clean_str_id(id: str) -> str:
60-
return id.replace("/", "%2F").replace("#", "%23")
60+
return quote(id, safe="")
6161

6262

6363
def sanitize_parameters(value):
6464
if isinstance(value, dict):
6565
return dict((k, sanitize_parameters(v)) for k, v in value.items())
6666
if isinstance(value, str):
67-
return value.replace("/", "%2F")
67+
return quote(value, safe="")
6868
return value
6969

7070

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy