Skip to content

Commit e557a20

Browse files
Allow single char version slugs.
1 parent c537b05 commit e557a20

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

readthedocs/builds/version_slug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
# Regex breakdown:
2828
# [a-z0-9] -- start with alphanumeric value
2929
# [-._a-z0-9] -- allow dash, dot, underscore, digit, lowercase ascii
30-
# +? -- allow multiple of those, but be not greedy about the matching
30+
# *? -- allow multiple of those, but be not greedy about the matching
3131
# (?: ... ) -- wrap everything so that the pattern cannot escape when used in
3232
# regexes.
33-
VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]+?)'
33+
VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]*?)'
3434

3535

3636
class VersionSlugField(models.CharField):

readthedocs/rtd_tests/tests/test_version_slug.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1+
import re
12
from django.test import TestCase
23

34
from builds.models import Version
45
from builds.version_slug import VersionSlugField
6+
from builds.version_slug import VERSION_SLUG_REGEX
57
from projects.models import Project
68

79

10+
class VersionSlugPatternTests(TestCase):
11+
pattern = re.compile('^{pattern}$'.format(pattern=VERSION_SLUG_REGEX))
12+
13+
def test_single_char(self):
14+
self.assertTrue(self.pattern.match('v'))
15+
self.assertFalse(self.pattern.match('.'))
16+
17+
def test_trailing_punctuation(self):
18+
self.assertTrue(self.pattern.match('with_'))
19+
self.assertTrue(self.pattern.match('with.'))
20+
self.assertTrue(self.pattern.match('with-'))
21+
self.assertFalse(self.pattern.match('with!'))
22+
23+
def test_multiple_words(self):
24+
self.assertTrue(self.pattern.match('release-1.0'))
25+
self.assertTrue(self.pattern.match('fix_this-and-that.'))
26+
27+
828
class VersionSlugFieldTests(TestCase):
929
fixtures = ["eric", "test_data"]
1030

0 commit comments

Comments
 (0)