slugify icon indicating copy to clipboard operation
slugify copied to clipboard

Fix out of bounds panic with empty separator

Open rgeraldporter opened this issue 3 years ago • 0 comments

Thanks a ton for this crate!

If one uses slugify!("hello world", separator = "") this will lead to a panic. My use case was part of a process to reduce a given HTML form element label down to a string that would be compliant for use in the name attribute of an HTML form -- generally all letters, no spaces. I was trying to be clever by seeking a slug library, and using an empty separator. In the end I still used the slugify, then replaced all the slugs with empty strings, but I figured I'd go back a recontribute a fix since this does cause a panic.

stderr:
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src/lib.rs:168:23

I added a test, updated docs to reflect that this usage now works.

rgeraldporter avatar Jan 18 '22 20:01 rgeraldporter