From a85a02f5d7df4fd2bc9f61aad85912a9bb017c62 Mon Sep 17 00:00:00 2001 From: Brent Martin Miller Date: Tue, 29 Oct 2024 16:56:29 -0400 Subject: [PATCH] feat: add support for macos 14+ filenames (#21) fix #20 --- src/dropzone.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dropzone.js b/src/dropzone.js index d8111f45a..56d9d8d28 100644 --- a/src/dropzone.js +++ b/src/dropzone.js @@ -422,12 +422,20 @@ export default class Dropzone extends Emitter { } // If @options.renameFile is a function, - // the function will be used to rename the file.name before appending it to the formData + // the function will be used to rename the file.name before appending it to the formData. + // MacOS 14+ screenshots contain narrow non-breaking space (U+202F) characters in filenames + // (e.g., "Screenshot 2024-01-30 at 10.32.07 AM.png" where the space after "07" and before "AM" is U+202F). + // This function now replaces these with regular spaces to prevent upload issues and maintain compatibility with MacOS _renameFile(file) { + const cleanFile = { + ...file, + name: file.name.replace(/\u202F/g, ' ') + }; + if (typeof this.options.renameFile !== "function") { - return file.name; + return cleanFile.name; } - return this.options.renameFile(file); + return this.options.renameFile(cleanFile); } // Returns a form that can be used as fallback if the browser does not support DragnDrop