From 868b876464ebc21a25d4b81c1eda4d4899d84674 Mon Sep 17 00:00:00 2001 From: Kwesi Aguillera Date: Thu, 21 Jul 2016 12:47:10 -0400 Subject: [PATCH] Fix and test for #3722 --- gratipay/models/community.py | 4 ++-- tests/py/test_fake_data.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gratipay/models/community.py b/gratipay/models/community.py index a3e0207515..efbbf2baf2 100644 --- a/gratipay/models/community.py +++ b/gratipay/models/community.py @@ -3,14 +3,14 @@ from postgres.orm import Model -name_pattern = re.compile(r'^[A-Za-z0-9,._ -]+$') +name_pattern = re.compile(r"^[A-Za-z0-9,._ '-]+$") def slugize(slug): """Convert a string to a string for an URL. """ assert name_pattern.match(slug) is not None slug = slug.lower() - for c in (' ', ',', '.', '_'): + for c in (' ', ',', '.', '_','\''): slug = slug.replace(c, '-') while '--' in slug: slug = slug.replace('--', '-') diff --git a/tests/py/test_fake_data.py b/tests/py/test_fake_data.py index df49351381..f36d143731 100644 --- a/tests/py/test_fake_data.py +++ b/tests/py/test_fake_data.py @@ -2,7 +2,7 @@ from gratipay.utils import fake_data from gratipay.testing import Harness - +from gratipay.models import community class TestFakeData(Harness): """ @@ -34,3 +34,9 @@ def test_fake_participant_identity(self): crusher = self.make_participant('crusher', email_address='crusher@example.com') country_id = fake_data.fake_participant_identity(crusher) assert [x.country.id for x in crusher.list_identity_metadata()] == [country_id] + + def test_slugize(self): + """ + Just a test to ensure that slugize can handle single quotes + """ + assert community.slugize("D'Amorebury") == "d-amorebury"