Skip to content
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
6 changes: 4 additions & 2 deletions lib/speakingurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,11 @@
// eliminate duplicate separators
// add separator
// trim separators from start and end
var escapedSeparator = escapeChars(separator);

result = result.replace(/\s+/g, separator)
.replace(new RegExp('\\' + separator + '+', 'g'), separator)
.replace(new RegExp('(^\\' + separator + '+|\\' + separator + '+$)', 'g'), '');
.replace(new RegExp('(?:' + escapedSeparator + ')+', 'g'), separator)
.replace(new RegExp('^(?:' + escapedSeparator + ')+|(?:' + escapedSeparator + ')+$', 'g'), '');

if (truncate && result.length > truncate) {
lucky = result.charAt(truncate) === separator;
Expand Down
21 changes: 21 additions & 0 deletions test/test-separator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ describe('getSlug separator', function () {

});

it('should separate with a multi-character separator', function (done) {

getSlug('Foo Bar Baz', {
separator: '..'
})
.should.eql('foo..bar..baz');

getSlug('Foo Bar Baz', {
separator: '++'
})
.should.eql('foo++bar++baz');

getSlug('Foo Bar Baz', {
separator: '()'
})
.should.eql('foo()bar()baz');

done();

});

it('should separate with non-whitespace, with trailing spaces', function (done) {

getSlug(' Foo Bar Baz ', {
Expand Down