Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#871: file extensions not enforced on Windows #904

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Also, sometimes a simple `flutter clean` and `flutter build` again with latest f
A clear and concise description of what the bug is. If the issue happens to be on Android, please make sure that it also happens with a different device/simulator and/or version.

**Platform**
- [] Android
- [] iOS
- [] Web
- [] Desktop (Go)

- [ ] Android
- [ ] iOS
- [ ] Web
- [ ] Desktop

**Platform OS version**
What version did it happen?
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.2.7

##### Desktop (macOS & Windows)
Fixes the issue under Windows that the user could select all file types even though a file type filter was enabled. This error existed because the user could select the entry `All Files (*.*)` in the file type filter dropdown. Also, fixes the bug under macOS that users could select files without file extension even when one of the pre-defined file type filters (audio, image, video, or media) was enabled. ([#871](https://github.com/miguelpruivo/flutter_file_picker/issues/871)).

## 4.2.6

##### Android
Expand Down
8 changes: 4 additions & 4 deletions lib/src/file_picker_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class FilePickerLinux extends FilePicker {
case FileType.any:
return '';
case FileType.audio:
return '*.mp3 *.wav *.midi *.ogg *.aac';
return '*.aac *.midi *.mp3 *.ogg *.wav';
case FileType.custom:
return '*.' + allowedExtensions!.join(' *.');
case FileType.image:
return '*.bmp *.gif *.jpg *.jpeg *.png';
return '*.bmp *.gif *.jpeg *.jpg *.png';
case FileType.media:
return '*.webm *.mpeg *.mkv *.mp4 *.avi *.mov *.flv *.jpg *.jpeg *.bmp *.gif *.png';
return '*.avi *.flv *.mkv *.mov *.mp4 *.mpeg *.webm *.wmv *.bmp *.gif *.jpeg *.jpg *.png';
case FileType.video:
return '*.webm *.mpeg *.mkv *.mp4 *.avi *.mov *.flv';
return '*.avi *.flv *.mkv *.mov *.mp4 *.mpeg *.webm *.wmv';
default:
throw Exception('unknown file type');
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/file_picker_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class FilePickerMacOS extends FilePicker {
case FileType.any:
return '';
case FileType.audio:
return '"", "mp3", "wav", "midi", "ogg", "aac"';
return '"aac", "midi", "mp3", "ogg", "wav"';
case FileType.custom:
return '"", "' + allowedExtensions!.join('", "') + '"';
case FileType.image:
return '"", "jpg", "jpeg", "bmp", "gif", "png"';
return '"bmp", "gif", "jpeg", "jpg", "png"';
case FileType.media:
return '"", "webm", "mpeg", "mkv", "mp4", "avi", "mov", "flv", "jpg", "jpeg", "bmp", "gif", "png"';
return '"avi", "flv", "mkv", "mov", "mp4", "mpeg", "webm", "wmv", "bmp", "gif", "jpeg", "jpg", "png"';
case FileType.video:
return '"", "webm", "mpeg", "mkv", "mp4", "avi", "mov", "flv"';
return '"avi", "flv", "mkv", "mov", "mp4", "mpeg", "webm", "wmv"';
default:
throw Exception('unknown file type');
}
Expand Down
10 changes: 5 additions & 5 deletions lib/src/windows/file_picker_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class FilePickerWindows extends FilePicker {
String fileTypeToFileFilter(FileType type, List<String>? allowedExtensions) {
switch (type) {
case FileType.any:
return '*.*\x00\x00';
return 'All Files (*.*)\x00*.*\x00\x00';
case FileType.audio:
return 'Audios (*.mp3)\x00*.mp3\x00All Files (*.*)\x00*.*\x00\x00';
return 'Audios (*.aac,*.midi,*.mp3,*.ogg,*.wav)\x00*.aac;*.midi;*.mp3;*.ogg;*.wav\x00\x00';
case FileType.custom:
return 'Files (*.${allowedExtensions!.join(',*.')})\x00*.${allowedExtensions.join(';*.')}\x00\x00';
case FileType.image:
return 'Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00';
return 'Images (*.bmp,*.gif,*.jpeg,*.jpg,*.png)\x00*.bmp;*.gif;*.jpeg;*.jpg;*.png\x00\x00';
case FileType.media:
return 'Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00';
return 'Videos (*.avi,*.flv,*.mkv,*.mov,*.mp4,*.mpeg,*.webm,*.wmv)\x00*.avi;*.flv;*.mkv;*.mov;*.mp4;*.mpeg;*.webm;*.wmv\x00Images (*.bmp,*.gif,*.jpeg,*.jpg,*.png)\x00*.bmp;*.gif;*.jpeg;*.jpg;*.png\x00\x00';
case FileType.video:
return 'Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00All Files (*.*)\x00*.*\x00\x00';
return 'Videos (*.avi,*.flv,*.mkv,*.mov,*.mp4,*.mpeg,*.webm,*.wmv)\x00*.avi;*.flv;*.mkv;*.mov;*.mp4;*.mpeg;*.webm;*.wmv\x00\x00';
default:
throw Exception('unknown file type');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 4.2.6
version: 4.2.7

dependencies:
flutter:
Expand Down
8 changes: 4 additions & 4 deletions test/file_picker_linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ void main() {

expect(
picker.fileTypeToFileFilter(FileType.audio, null),
equals('*.mp3 *.wav *.midi *.ogg *.aac'),
equals('*.aac *.midi *.mp3 *.ogg *.wav'),
);

expect(
picker.fileTypeToFileFilter(FileType.image, null),
equals('*.bmp *.gif *.jpg *.jpeg *.png'),
equals('*.bmp *.gif *.jpeg *.jpg *.png'),
);

expect(
picker.fileTypeToFileFilter(FileType.media, null),
equals(
'*.webm *.mpeg *.mkv *.mp4 *.avi *.mov *.flv *.jpg *.jpeg *.bmp *.gif *.png',
'*.avi *.flv *.mkv *.mov *.mp4 *.mpeg *.webm *.wmv *.bmp *.gif *.jpeg *.jpg *.png',
),
);

expect(
picker.fileTypeToFileFilter(FileType.video, null),
equals('*.webm *.mpeg *.mkv *.mp4 *.avi *.mov *.flv'),
equals('*.avi *.flv *.mkv *.mov *.mp4 *.mpeg *.webm *.wmv'),
);
});

Expand Down
14 changes: 10 additions & 4 deletions test/file_picker_macos_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ void main() {

expect(
picker.fileTypeToFileFilter(FileType.audio, null),
equals('"", "mp3", "wav", "midi", "ogg", "aac"'),
equals('"aac", "midi", "mp3", "ogg", "wav"'),
);

expect(
picker.fileTypeToFileFilter(FileType.image, null),
equals('"", "jpg", "jpeg", "bmp", "gif", "png"'),
equals('"bmp", "gif", "jpeg", "jpg", "png"'),
);

expect(
picker.fileTypeToFileFilter(FileType.media, null),
equals(
'"", "webm", "mpeg", "mkv", "mp4", "avi", "mov", "flv", "jpg", "jpeg", "bmp", "gif", "png"',
'"avi", "flv", "mkv", "mov", "mp4", "mpeg", "webm", "wmv", "bmp", "gif", "jpeg", "jpg", "png"',
),
);

expect(
picker.fileTypeToFileFilter(FileType.video, null),
equals('"", "webm", "mpeg", "mkv", "mp4", "avi", "mov", "flv"'),
equals('"avi", "flv", "mkv", "mov", "mp4", "mpeg", "webm", "wmv"'),
);
});

Expand All @@ -42,6 +42,12 @@ void main() {
() {
final picker = FilePickerMacOS();

// TODO: the first empty file type ("", ) is required in some cases, e.g.
// when filtering for *.dart and other special file types. Unfortunately,
// the empty file type enables the selection of files without extension.
// In other cases, e.g. when filtering for *.png files, it isn't required
// to provide the empty file type. We need to find a solution to make the
// filter work without having to provide an empty file type first.
expect(
picker.fileTypeToFileFilter(FileType.custom, ['dart']),
equals('"", "dart"'),
Expand Down
11 changes: 6 additions & 5 deletions test/file_picker_windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@ void main() {

expect(
picker.fileTypeToFileFilter(FileType.any, null),
equals('*.*\x00\x00'),
equals('All Files (*.*)\x00*.*\x00\x00'),
);

expect(
picker.fileTypeToFileFilter(FileType.audio, null),
equals('Audios (*.mp3)\x00*.mp3\x00All Files (*.*)\x00*.*\x00\x00'),
equals(
'Audios (*.aac,*.midi,*.mp3,*.ogg,*.wav)\x00*.aac;*.midi;*.mp3;*.ogg;*.wav\x00\x00'),
);

expect(
picker.fileTypeToFileFilter(FileType.image, null),
equals(
'Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00',
'Images (*.bmp,*.gif,*.jpeg,*.jpg,*.png)\x00*.bmp;*.gif;*.jpeg;*.jpg;*.png\x00\x00',
),
);

expect(
picker.fileTypeToFileFilter(FileType.media, null),
equals(
'Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00',
'Videos (*.avi,*.flv,*.mkv,*.mov,*.mp4,*.mpeg,*.webm,*.wmv)\x00*.avi;*.flv;*.mkv;*.mov;*.mp4;*.mpeg;*.webm;*.wmv\x00Images (*.bmp,*.gif,*.jpeg,*.jpg,*.png)\x00*.bmp;*.gif;*.jpeg;*.jpg;*.png\x00\x00',
),
);

expect(
picker.fileTypeToFileFilter(FileType.video, null),
equals(
'Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00All Files (*.*)\x00*.*\x00\x00',
'Videos (*.avi,*.flv,*.mkv,*.mov,*.mp4,*.mpeg,*.webm,*.wmv)\x00*.avi;*.flv;*.mkv;*.mov;*.mp4;*.mpeg;*.webm;*.wmv\x00\x00',
),
);
});
Expand Down