From 8942f22a9b6ee03302289a97024b88c31280546c Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 14 Mar 2023 18:19:51 +0000 Subject: [PATCH] FileChooser: Avoid setting default extension to filename Fixes a bug on Windows when opening a FileChooser with the following arguments. FileChooser ("", "C:\path\to\file", // filename 'file' doesn't contain '.' "", // all extensions are allowed true); The expected behaviour is that the initially-displayed filename is "file". The actual behaviour was that the initially-displayed filename was "file.file". --- .../native/juce_win32_FileChooser.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp index 6f320ba777..fbd57db499 100644 --- a/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp +++ b/modules/juce_gui_basics/native/juce_win32_FileChooser.cpp @@ -581,19 +581,20 @@ private: String getDefaultFileExtension (const String& filename) const { - auto extension = filename.fromLastOccurrenceOf (".", false, false); + const auto extension = filename.contains (".") ? filename.fromLastOccurrenceOf (".", false, false) + : String(); - if (extension.isEmpty()) - { - auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'"); - tokens.trim(); - tokens.removeEmptyStrings(); + if (! extension.isEmpty()) + return extension; - if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty()) - extension = tokens[0].fromFirstOccurrenceOf (".", false, false); - } + auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'"); + tokens.trim(); + tokens.removeEmptyStrings(); + + if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty()) + return tokens[0].fromFirstOccurrenceOf (".", false, false); - return extension; + return {}; } //==============================================================================