Skip to content

Commit

Permalink
Let identifier_friendly cope with unicode in identifiers (#2560)
Browse files Browse the repository at this point in the history
This fixes rendering of /projects/$proj/versions/ when a branch
name contains a character which cannot be expressed in ascii.

Fixes #2506
  • Loading branch information
PeterJCLaw authored and berkerpeksag committed Jan 22, 2017
1 parent 6b30a12 commit 2c744d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def delete(self, *args, **kwargs):
def identifier_friendly(self):
'''Return display friendly identifier'''
re_sha = re.compile(r'^[0-9a-f]{40}$', re.I)
if re_sha.match(str(self.identifier)):
if re_sha.match(self.identifier):
return self.identifier[:8]
return self.identifier

Expand Down
12 changes: 12 additions & 0 deletions readthedocs/rtd_tests/tests/test_version_commit_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@


class VersionCommitNameTests(TestCase):
def test_branch_name_unicode_non_ascii(self):
unicode_name = 'abc_\xd1\x84_\xe2\x99\x98'.decode('utf-8')
version = new(Version, identifier=unicode_name, type=BRANCH)
self.assertEqual(version.identifier_friendly, unicode_name)

def test_branch_name_made_friendly_when_sha(self):
commit_hash = '3d92b728b7d7b842259ac2020c2fa389f13aff0d'
version = new(Version, identifier=commit_hash,
slug=STABLE, verbose_name=STABLE, type=TAG)
# we shorten commit hashes to keep things readable
self.assertEqual(version.identifier_friendly, '3d92b728')

def test_branch_name(self):
version = new(Version, identifier='release-2.5.x',
slug='release-2.5.x', verbose_name='release-2.5.x',
Expand Down

0 comments on commit 2c744d2

Please sign in to comment.