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

fix: convert # to %23 in URLs#790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
max-wittig merged 1 commit intomasterfromfix/779
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletionsgitlab/mixins.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
from gitlab import cli
from gitlab import exceptions as exc
from gitlab import types as g_types
from gitlab import utils


class GetMixin(object):
Expand All@@ -42,7 +43,7 @@ def get(self, id, lazy=False, **kwargs):
GitlabGetError: If the server cannot perform the request
"""
if not isinstance(id, int):
id =id.replace("/", "%2F")
id =utils.clean_str_id(id)
path = "%s/%s" % (self.path, id)
if lazy is True:
return self._obj_cls(self, {self._obj_cls._id_attr: id})
Expand DownExpand Up@@ -299,7 +300,7 @@ def set(self, key, value, **kwargs):
Returns:
obj: The created/updated attribute
"""
path = "%s/%s" % (self.path,key.replace("/", "%2F"))
path = "%s/%s" % (self.path,utils.clean_str_id(key))
data = {"value": value}
server_data = self.gitlab.http_put(path, post_data=data, **kwargs)
return self._obj_cls(self, server_data)
Expand All@@ -322,7 +323,7 @@ def delete(self, id, **kwargs):
path = self.path
else:
if not isinstance(id, int):
id =id.replace("/", "%2F")
id =utils.clean_str_id(id)
path = "%s/%s" % (self.path, id)
self.gitlab.http_delete(path, **kwargs)

Expand Down
43 changes: 43 additions & 0 deletionsgitlab/tests/test_utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 Gauvain Pocentek <gauvain@pocentek.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# 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/>.

try:
import unittest
except ImportError:
import unittest2 as unittest

from gitlab import utils


class TestUtils(unittest.TestCase):
def test_clean_str_id(self):
src = "nothing_special"
dest = "nothing_special"
self.assertEqual(dest, utils.clean_str_id(src))

src = "foo#bar/baz/"
dest = "foo%23bar%2Fbaz%2F"
self.assertEqual(dest, utils.clean_str_id(src))

def test_sanitized_url(self):
src = "http://localhost/foo/bar"
dest = "http://localhost/foo/bar"
self.assertEqual(dest, utils.sanitized_url(src))

src = "http://localhost/foo.bar.baz"
dest = "http://localhost/foo%2Ebar%2Ebaz"
self.assertEqual(dest, utils.sanitized_url(src))
4 changes: 4 additions & 0 deletionsgitlab/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,10 @@ def copy_dict(dest, src):
dest[k] = v


def clean_str_id(id):
return id.replace("/", "%2F").replace("#", "%23")


def sanitized_url(url):
parsed = six.moves.urllib.parse.urlparse(url)
new_path = parsed.path.replace(".", "%2E")
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp