Skip to content

Commit

Permalink
Improve file name validator to support -, (, ), comma and space
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 13, 2023
1 parent 4543de1 commit c84bcb6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/lib/api/file_system/file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> _findAvailableName(
Expand Down Expand Up @@ -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());
}
}

Expand Down
5 changes: 1 addition & 4 deletions app/lib/views/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ class _FilesViewState extends State<FilesView> {
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(
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/74.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c84bcb6

Please sign in to comment.