Skip to content
14 changes: 1 addition & 13 deletions src/ParentWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,7 @@ const Option = (props) => {

export const sanitizePath = (path) => {
const replacement = '-';
const sanitizedPath = slugify(path.toLowerCase(), replacement);

// Remove any doubled or leading/trailing replacement characters (that were added in the sanitizers).
const doubleReplacement = new RegExp(`(?:${replacement})+`, 'g');
const trailingReplacement = new RegExp(`${replacement}$`);
const leadingReplacement = new RegExp(`^${replacement}`);

const normalizedPath = sanitizedPath
.replace(doubleReplacement, replacement)
.replace(leadingReplacement, '')
.replace(trailingReplacement, '');

return normalizedPath;
return slugify(path.replace(/\./g, replacement), { replacement, lower: true });
};

export class ParentControl extends React.Component {
Expand Down
4 changes: 4 additions & 0 deletions src/ParentWidget.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ describe('sanitizePath', () => {
it('should keep diacritis and remove whitespace, trailing and leading characters', () => {
expect(sanitizePath('?ăștia sunteți voi ? ')).toBe('astia-sunteti-voi');
});

it('should remove "."s', () => {
expect(sanitizePath('who are.we')).toBe('who-are-we');
});
});