fix: replace . with - in slugs (#39168)

This commit is contained in:
Oliver Eyton-Williams
2020-07-03 16:58:53 +02:00
committed by GitHub
parent 7ed1d52001
commit 52ecb14b0f
2 changed files with 7 additions and 3 deletions

View File

@ -2,7 +2,7 @@ exports.dasherize = function dasherize(name) {
return ('' + name)
.toLowerCase()
.trim()
.replace(/\s/g, '-')
.replace(/\s|\./g, '-')
.replace(/[^a-z\d\-.]/g, '');
};

View File

@ -14,12 +14,16 @@ describe('dasherize', () => {
expect(dasherize('the space between')).toBe('the-space--between');
});
it('converts dots to dashes', () => {
expect(dasherize('the..dots.. between')).toBe('the--dots---between');
});
it('trims off surrounding whitespace', () => {
expect(dasherize(' the space between ')).toBe('the-space--between');
});
it('removes everything except letters, numbers, - and .', () => {
expect(dasherize('1a!"£$%^*()_+=-.b2')).toBe('1a-.b2');
it('removes everything except letters, numbers and -', () => {
expect(dasherize('1a!"£$%^*()_+=-.b2')).toBe('1a--b2');
});
});