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

fix: support mixed-case extensions in Linux file dialogs #34016

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions shell/browser/ui/file_dialog_gtk.cc
Expand Up @@ -31,6 +31,25 @@ namespace {
static const int kPreviewWidth = 256;
static const int kPreviewHeight = 512;

std::string MakeCaseInsensitivePattern(const std::string& extension) {
std::string pattern("*.");

for (std::size_t i = 0, n = extension.size(); i < n; i++) {
char ch = extension[i];
if (!base::IsAsciiAlpha(ch)) {
pattern.push_back(ch);
continue;
}

pattern.push_back('[');
pattern.push_back(base::ToLowerASCII(ch));
pattern.push_back(base::ToUpperASCII(ch));
pattern.push_back(']');
}

return pattern;
}

class FileChooserDialog {
public:
FileChooserDialog(GtkFileChooserAction action, const DialogSettings& settings)
Expand Down Expand Up @@ -252,12 +271,8 @@ void FileChooserDialog::AddFilters(const Filters& filters) {
GtkFileFilter* gtk_filter = gtk_file_filter_new();

for (const auto& extension : filter.second) {
// guarantee a pure lowercase variant
std::string file_extension = base::ToLowerASCII("*." + extension);
gtk_file_filter_add_pattern(gtk_filter, file_extension.c_str());
// guarantee a pure uppercase variant
file_extension = base::ToUpperASCII("*." + extension);
gtk_file_filter_add_pattern(gtk_filter, file_extension.c_str());
std::string pattern = MakeCaseInsensitivePattern(extension);
gtk_file_filter_add_pattern(gtk_filter, pattern.c_str());
}

gtk_file_filter_set_name(gtk_filter, filter.first.c_str());
Expand Down