From c84bcb642205a1db2a10887597e5141aefe66af6 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Fri, 13 Oct 2023 10:58:14 +0200 Subject: [PATCH] Improve file name validator to support -, (, ), comma and space --- app/lib/api/file_system/file_system.dart | 5 +++-- app/lib/views/files.dart | 5 +---- fastlane/metadata/android/en-US/changelogs/74.txt | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/lib/api/file_system/file_system.dart b/app/lib/api/file_system/file_system.dart index 80dca972c627..88a6af621414 100644 --- a/app/lib/api/file_system/file_system.dart +++ b/app/lib/api/file_system/file_system.dart @@ -19,7 +19,7 @@ abstract class GeneralFileSystem { RemoteStorage? get remote => null; String convertNameToFile(String name) { - return '${name.replaceAll(RegExp(r'[^a-zA-Z0-9]'), '_')}.bfly'; + return name.replaceAll(RegExp(r'[^a-zA-Z0-9\-_() ,]'), '_'); } Future _findAvailableName( @@ -180,7 +180,8 @@ abstract class DocumentFileSystem extends GeneralFileSystem { if (path.endsWith('/')) { path = path.substring(0, path.length - 1); } - return createFile('$path/${document.name}.bfly', document.save()); + return createFile('$path/${convertNameToFile(document.name ?? '')}.bfly', + document.save()); } } diff --git a/app/lib/views/files.dart b/app/lib/views/files.dart index b3441059f791..f5a18ada5084 100644 --- a/app/lib/views/files.dart +++ b/app/lib/views/files.dart @@ -295,10 +295,7 @@ class _FilesViewState extends State { if (asset == null) return; final path = _locationController.text; var newPath = - '$path/${_fileSystem.convertNameToFile(name!)}'; - if (!newPath.endsWith('.bfly')) { - newPath += '.bfly'; - } + '$path/${_fileSystem.convertNameToFile(name!)}.bfly'; await _fileSystem.updateDocument( newPath, asset.createDocument( diff --git a/fastlane/metadata/android/en-US/changelogs/74.txt b/fastlane/metadata/android/en-US/changelogs/74.txt index 2f7ba0f0c2bb..264234b1caac 100644 --- a/fastlane/metadata/android/en-US/changelogs/74.txt +++ b/fastlane/metadata/android/en-US/changelogs/74.txt @@ -12,6 +12,7 @@ * Fix tool reordering * Improve default pattern templates values * Improve documentation +* Improve file name validator to support -, (, ), comma and space * Switch back to flutter beta View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.10 \ No newline at end of file