changeset 6662:182f46d62ab4

repository: fix crash when forking repositories with unicode names
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 30 May 2017 02:59:45 +0200
parents 5eb412b5d365
children 8390da12aa16
files kallithea/lib/vcs/backends/git/repository.py kallithea/lib/vcs/backends/hg/repository.py kallithea/tests/functional/test_forks.py
diffstat 3 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/git/repository.py	Tue May 30 02:59:45 2017 +0200
+++ b/kallithea/lib/vcs/backends/git/repository.py	Tue May 30 02:59:45 2017 +0200
@@ -30,7 +30,7 @@
     BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError,
     RepositoryError, TagAlreadyExistError, TagDoesNotExistError
 )
-from kallithea.lib.vcs.utils import safe_unicode, makedate, date_fromtimestamp
+from kallithea.lib.vcs.utils import safe_str, safe_unicode, makedate, date_fromtimestamp
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.vcs.utils.ordered_dict import OrderedDict
 from kallithea.lib.vcs.utils.paths import abspath, get_user_home
@@ -328,7 +328,7 @@
         Returns normalized url. If schema is not given, would fall to
         filesystem (``file:///``) schema.
         """
-        url = str(url)
+        url = safe_str(url)
         if url != 'default' and not '://' in url:
             url = ':///'.join(('file', url))
         return url
--- a/kallithea/lib/vcs/backends/hg/repository.py	Tue May 30 02:59:45 2017 +0200
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Tue May 30 02:59:45 2017 +0200
@@ -349,7 +349,7 @@
 
         try:
             if src_url:
-                url = str(self._get_url(src_url))
+                url = safe_str(self._get_url(src_url))
                 opts = {}
                 if not update_after_clone:
                     opts.update({'noupdate': True})
@@ -481,7 +481,7 @@
         to filesystem
         (``file:///``) schema.
         """
-        url = str(url)
+        url = safe_str(url)
         if url != 'default' and not '://' in url:
             url = "file:" + urllib.pathname2url(url)
         return url
--- a/kallithea/tests/functional/test_forks.py	Tue May 30 02:59:45 2017 +0200
+++ b/kallithea/tests/functional/test_forks.py	Tue May 30 02:59:45 2017 +0200
@@ -161,7 +161,28 @@
         fork_repo = Repository.get_by_repo_name(safe_unicode(fork_name))
         assert fork_repo
 
-        # remove this fork
+        # fork the fork
+        fork_name_2 = safe_str(self.REPO_FORK + u'-blåbærgrød')
+        creation_args = {
+            'repo_name': fork_name_2,
+            'repo_group': u'-1',
+            'fork_parent_id': fork_repo.repo_id,
+            'repo_type': self.REPO_TYPE,
+            'description': 'unicode repo 2',
+            'private': 'False',
+            'landing_rev': 'rev:tip',
+            '_authentication_token': self.authentication_token()}
+        self.app.post(url(controller='forks', action='fork_create',
+                          repo_name=fork_name), creation_args)
+        response = self.app.get(url(controller='forks', action='forks',
+                                    repo_name=fork_name))
+        response.mustcontain(
+            """<a href="/%s">%s</a>""" % (urllib.quote(fork_name_2), fork_name_2)
+        )
+
+        # remove these forks
+        response = self.app.post(url('delete_repo', repo_name=fork_name_2),
+            params={'_authentication_token': self.authentication_token()})
         response = self.app.post(url('delete_repo', repo_name=fork_name),
             params={'_authentication_token': self.authentication_token()})