Skip to content

Commit 7de1fdd

Browse files
fix: multiple extension filters on macOS (electron#23451)
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
1 parent 6f6ca44 commit 7de1fdd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

shell/browser/ui/file_dialog_mac.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ void SetAllowedFileTypes(NSSavePanel* dialog, const Filters& filters) {
9191
for (const Filter& filter : filters) {
9292
NSMutableSet* file_type_set = [NSMutableSet set];
9393
[filter_names addObject:@(filter.first.c_str())];
94-
for (const std::string& ext : filter.second) {
94+
for (std::string ext : filter.second) {
95+
// macOS is incapable of understanding multiple file extensions,
96+
// so we need to tokenize the extension that's been passed in.
97+
// We want to err on the side of allowing files, so we pass
98+
// along only the final extension ('tar.gz' => 'gz').
99+
auto pos = ext.rfind('.');
100+
if (pos != std::string::npos) {
101+
ext.erase(0, pos + 1);
102+
}
103+
95104
[file_type_set addObject:@(ext.c_str())];
96105
}
97106
[file_types_list addObject:[file_type_set allObjects]];

0 commit comments

Comments
 (0)