From 17de872831b2be62e0ad21555a87be0546ca2ed1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 19 2016 13:28:16 +0000 Subject: [PATCH 1/2] Add unit-tests to test viewing a file with a non-ascii name --- diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 119279b..afed1e3 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -1371,6 +1371,21 @@ class PagureFlaskRepotests(tests.Modeltests): output = self.app.get('/test/blob/master/f/folder1/testfoo.jpg') self.assertEqual(output.status_code, 404) + # View file with a non-ascii name + tests.add_commit_git_repo( + os.path.join(tests.HERE, 'test.git'), + ncommits=1, filename='Šource') + output = self.app.get('/test/blob/master/f/Šource') + self.assertEqual(output.status_code, 200) + self.assertIn('  Šource', output.data) + self.assertIn('', output.data) + self.assertIn( + '', output.data) + self.assertIn( + '', + output.data) + # Add a fork of a fork item = pagure.lib.model.Project( user_id=1, # pingou From 4ef2cd32e04e0ff3ba313b7f5ec312a79d0f8b91 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 19 2016 13:28:17 +0000 Subject: [PATCH 2/2] Fix viewing a file with a non-ascii name --- diff --git a/pagure/__init__.py b/pagure/__init__.py index c7c73db..153a89d 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -385,7 +385,8 @@ def __get_file_in_tree(repo_obj, tree, filepath, bail_on_tree=False): if isinstance(tree, pygit2.Blob): return for entry in tree: - if entry.name == filename: + fname = entry.name.decode('utf-8') + if fname == filename: if len(filepath) == 1: blob = repo_obj.get(entry.id) # If we can't get the content (for example: an empty folder) diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index 77c1247..a7a562d 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -413,7 +413,7 @@ def text_wraps(dictionary): @APP.template_filter('unicode') def convert_unicode(text): - if isinstance(text, basestring): + if isinstance(text, str): return text.decode("utf8") else: return text
Row 0