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

Fix slugify when str is empty/none (BugFix) #1768

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions checkbox-support/checkbox_support/helpers/slugify.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def slugify(_string):
Transform any string to one that can be used in filenames and Python
identifers.
"""
if not _string:
return _string

valid_chars = frozenset(
"_{}{}".format(string.ascii_letters, string.digits)
)
Expand Down
8 changes: 8 additions & 0 deletions checkbox-support/checkbox_support/tests/test_slugify.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ def test_slugify_dots(self):
def test_slugify_string_starting_with_number(self):
result = slugify("123abc")
self.assertEqual(result, "_123abc")

def test_slugify_empty_string(self):
result = slugify("")
self.assertEqual(result, "")

def test_slugify_none(self):
result = slugify(None)
self.assertEqual(result, None)
Loading