talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

Module stops on empty slug #24

Closed wmthor closed 7 years ago

wmthor commented 7 years ago

The slug becomes empty when the text is empty or when its contains entirely foreign characters. It slugifies to an empty string, therefore doesn't get past this point.

if (!newSlug.length && options.index_sparse) {
    doc.set(options.field, undefined);
    return next();
}

Perhaps there can be a fallback such as returning an empty separator, e.g. "-"?

talha-asad commented 7 years ago

Yes that, or an incrementing number could work, I'll accept a PR for this. I will not be able to contribute to this project for a little while.

talha-asad commented 7 years ago

This is not an issues anymore, if you still see this problem, provide a reproduction.