un33k/python-slugify

Issue with separator

Closed this issue · 3 comments

In [2]: slugify("aaa bbb-ccc")
Out[2]: 'aaa-bbb-ccc'

In [3]: slugify("aaa bbb-ccc", separator='.')
Out[3]: 'aaa.bbb.ccc'

I was expecting to get 'aaa.bbb-ccc'.

un33k commented

This package removes any non-alpha numeric characters and replaces them by the separator of your choice or '-' if you don't provide one.

But '-' is in the allowed char regex:
ALLOWED_CHARS_PATTERN = re.compile(r'[^-a-z0-9]+')
ALLOWED_CHARS_PATTERN_WITH_UPPERCASE = re.compile(r'[^-a-zA-Z0-9]+')

So it's not logic to not keep them.

un33k commented

Yes, - is allowed as the default separator, which is a general form of a slug in URLS . However due to popular requests, the separator overwrite was added ... and at the end of the function, the optional separator that is passed in as a param, will be swapped in with the default one. The package is doing what is should, and if you are looking for a new feature, please create a feature request. With that said, for backward compatibility, this behavior will remain.