Skip to content

Commit

Permalink
Merge pull request #3 from mik3y/mikey/bugfix
Browse files Browse the repository at this point in the history
bugfix: fix an error with prefixes greater than 2 characters (:facepalm:)
  • Loading branch information
mik3y authored Dec 14, 2022
2 parents 475c661 + d850699 commit 0d0c495
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_spicy_id/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

# Validates acceptable values for the `prefix=` field parameter.
LEGAL_PREFIX_RE = re.compile("^[a-zA-Z][0-9a-z-A-Z]?$")
LEGAL_PREFIX_RE = re.compile("^[a-zA-Z][0-9a-z-A-Z]*$")


def get_regex(preamble, codec, pad, char_len):
Expand Down
18 changes: 18 additions & 0 deletions django_spicy_id/tests/fields_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@
from django.test import TestCase

from django_spicy_id import MalformedSpicyIdError, SpicyAutoField
from django_spicy_id.fields import LEGAL_PREFIX_RE
from django_spicy_id.tests import models


class TestFields(TestCase):
def test_prefix_re(self):
legal_prefixes = (
"e",
"ex",
"ExampleThatsReallyLong",
)
for p in legal_prefixes:
self.assertIsNotNone(LEGAL_PREFIX_RE.match(p))

illegal_prefixes = (
"",
"🆒",
"9gag",
)
for p in illegal_prefixes:
self.assertIsNone(LEGAL_PREFIX_RE.match(p))

def test_field_configuration(self):
with self.assertRaisesMessage(ImproperlyConfigured, "unknown encoding"):
SpicyAutoField(prefix="yo", encoding="doop")
Expand Down

0 comments on commit 0d0c495

Please sign in to comment.