From e557a2075573275a18ef7841ddf2ea768ae919d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20M=C3=BCllegger?= Date: Mon, 6 Jul 2015 12:01:13 +0200 Subject: [PATCH] Allow single char version slugs. --- readthedocs/builds/version_slug.py | 4 ++-- .../rtd_tests/tests/test_version_slug.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/readthedocs/builds/version_slug.py b/readthedocs/builds/version_slug.py index 871edf5b826..bbc4ada4a52 100644 --- a/readthedocs/builds/version_slug.py +++ b/readthedocs/builds/version_slug.py @@ -27,10 +27,10 @@ # Regex breakdown: # [a-z0-9] -- start with alphanumeric value # [-._a-z0-9] -- allow dash, dot, underscore, digit, lowercase ascii -# +? -- allow multiple of those, but be not greedy about the matching +# *? -- allow multiple of those, but be not greedy about the matching # (?: ... ) -- wrap everything so that the pattern cannot escape when used in # regexes. -VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]+?)' +VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]*?)' class VersionSlugField(models.CharField): diff --git a/readthedocs/rtd_tests/tests/test_version_slug.py b/readthedocs/rtd_tests/tests/test_version_slug.py index 7ed1d212f31..3277149cefb 100644 --- a/readthedocs/rtd_tests/tests/test_version_slug.py +++ b/readthedocs/rtd_tests/tests/test_version_slug.py @@ -1,10 +1,30 @@ +import re from django.test import TestCase from builds.models import Version from builds.version_slug import VersionSlugField +from builds.version_slug import VERSION_SLUG_REGEX from projects.models import Project +class VersionSlugPatternTests(TestCase): + pattern = re.compile('^{pattern}$'.format(pattern=VERSION_SLUG_REGEX)) + + def test_single_char(self): + self.assertTrue(self.pattern.match('v')) + self.assertFalse(self.pattern.match('.')) + + def test_trailing_punctuation(self): + self.assertTrue(self.pattern.match('with_')) + self.assertTrue(self.pattern.match('with.')) + self.assertTrue(self.pattern.match('with-')) + self.assertFalse(self.pattern.match('with!')) + + def test_multiple_words(self): + self.assertTrue(self.pattern.match('release-1.0')) + self.assertTrue(self.pattern.match('fix_this-and-that.')) + + class VersionSlugFieldTests(TestCase): fixtures = ["eric", "test_data"]