Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize "." in sanitizedPaths #403

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
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');
});
});