Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41dc7bf

Browse files
committed
fix: handle tags like debian/2%2.6-21 as identifiers
Git refnames are relatively free-form and can contain all sort forspecial characters, not just `/ and `#`, seehttp://git-scm.com/docs/git-check-ref-formatIn particular, Debian's DEP-14 standard for storing packaging in gitrepositories mandates the use of the `%` character in tags in somecases like `debian/2%2.6-21`.Unfortunately python-gitlab currently only escapes `/` to `%2F` and insome cases `#` to `%23`. This means that when using the commit API toretrieve information about the `debian/2%2.6-21` tag only the slash isescaped before being inserted in the URL path and the `%` is leftuntouched, resulting in something like`/api/v4/projects/123/repository/commits/debian%2F2%2.6-21`. Whenurllib3 seees that it detects the invalid `%` escape and then urlencodesthe whole string, resulting in`/api/v4/projects/123/repository/commits/debian%252F2%252.6-21`, wherethe original `/` got escaped twice and produced `%252F`.To avoid the issue, fully urlencode identifiers and parameters to avoidthe urllib3 auto-escaping in all cases.Signed-off-by: Emanuele Aina <emanuele.aina@collabora.com>
1 parentaa13214 commit41dc7bf

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
assertdest==utils.clean_str_id(src)
2929

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

3135
deftest_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+
deftest_sanitize_parameters_slash_and_percent():
56+
assert"foo%2Fbar%25quuz"==utils.sanitize_parameters("foo/bar%quuz")
57+
58+
5159
deftest_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
fromtypingimportAny,Callable,Dict,Optional
19-
fromurllib.parseimporturlparse
19+
fromurllib.parseimportquote,urlparse
2020

2121
importrequests
2222

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

5858

5959
defclean_str_id(id:str)->str:
60-
returnid.replace("/","%2F").replace("#","%23")
60+
returnquote(id,safe="")
6161

6262

6363
defsanitize_parameters(value):
6464
ifisinstance(value,dict):
6565
returndict((k,sanitize_parameters(v))fork,vinvalue.items())
6666
ifisinstance(value,str):
67-
returnvalue.replace("/","%2F")
67+
returnquote(value,safe="")
6868
returnvalue
6969

7070

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp