Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kinto lowercase and slugify collection_name and bucket_name #33

Merged
merged 2 commits into from Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions kinto_client/tests/test_utils.py
Expand Up @@ -18,6 +18,10 @@ def test_slugify_removes_unknown_characters(self):
def test_slugify_replaces_equivalent_chars(self):
assert utils.slugify(u'chârs') == 'chars'

def test_slugify_do_no_modify_valid_ids(self):
for value in ['en-US', 'en_GB']:
assert utils.slugify(value) == value

def test_urljoin_can_join_with_trailing_slash(self):
url = utils.urljoin("http://localhost/", "v1")
self.assertEquals(url, "http://localhost/v1")
Expand Down
9 changes: 8 additions & 1 deletion kinto_client/utils.py
Expand Up @@ -3,12 +3,19 @@
from unidecode import unidecode
import six

VALID_SLUG_REGEXP = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$')


def slugify(value):
"""Normalizes string, converts to lowercase, removes non-alpha characters
and converts spaces to hyphens.
"""
value = unidecode(six.text_type(value))
value = six.text_type(value)
# Do not slugify valid values.
if VALID_SLUG_REGEXP.match(value):
return value

value = unidecode(value)
if isinstance(value, six.binary_type):
value = value.decode('ascii') # pragma: nocover
value = unicodedata.normalize('NFKD', value).lower()
Expand Down