Skip to content

Commit

Permalink
🐛bug: fix accented filenames breaking file send #3071
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Mar 23, 2023
1 parent da74535 commit 2973a77
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ export function rmFileAsync(file: string) {
*/
export const assertFile : (file: AdvancedFile | Buffer, outfileName: string, desiredOutputType: keyof typeof FileOutputTypes, requestConfig ?: any ) => Promise<string | Buffer | Readable > = async (file, outfileName, desiredOutputType, requestConfig) => {
let inputType;
outfileName = sanitizeAccentedChars(outfileName)
if(typeof file == 'string') {
if(isDataURL(file)) inputType = FileInputTypes.DATA_URL
else if(isBase64(file)) inputType = FileInputTypes.BASE_64
Expand Down Expand Up @@ -458,4 +459,17 @@ export const fixPath : (_path : string) => string = ( _path : string) => {
_path = _path.replace("~",homedir())
_path = _path.includes('./') ? path.join(process.cwd(), _path) : _path;
return _path;
}
}

/**
*
* Accented filenames break file sending in docker containers. This is used to replace accented chars in strings to prevent file sending failures.
*
* @param input The raw string
* @returns A sanitized string with all accented chars removed
*/
export const sanitizeAccentedChars : (input : string) => string = (input: string) => {
return input
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '');
}

0 comments on commit 2973a77

Please sign in to comment.