Skip to content

Commit

Permalink
Improve regex to replace letters with accents
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Feb 14, 2022
1 parent 85f094a commit 1b9e2b4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jsapp/js/components/submissions/submissionUtils.ts
Expand Up @@ -478,6 +478,7 @@ export function getMediaAttachment(
fileName: string
): string | SubmissionAttachment {
const validFileName = getValidFilename(fileName);
console.log('validFileName', validFileName);
let mediaAttachment: string | SubmissionAttachment = t('Could not find ##fileName##').replace(
'##fileName##',
fileName,
Expand All @@ -487,9 +488,9 @@ export function getMediaAttachment(
if (attachment.filename.includes(validFileName)) {
mediaAttachment = attachment;
}
});
})

return mediaAttachment;
return mediaAttachment
}

/**
Expand All @@ -502,7 +503,7 @@ export function getValidFilename(
): string {
return fileName.normalize('NFD').replace(/\p{Diacritic}/gu, '')
.replace(/ /g, '_')
.replace(/[^-\w\.]/g, '');
.replace(/[^\p{L}\p{M}\.\d_-]/gu, '')
}

export default {
Expand Down

0 comments on commit 1b9e2b4

Please sign in to comment.