Fix using *.* in wxDir under MSW

Using "*.*" as a wildcard is supposed to match everything under MSW, but
ever since the changes of 4daceaacbd (Check that files returned from
wxDir::FindXXX() match the filter., 2013-04-08, see #3432) it only
matched the files with extension because we double-checked the match
returned by the native MSW function (which does handle "*.*" correctly)
using our own wxString::Matches() which doesn't handle it specially.

Fix this by skipping the call to Matches() when "*.*" is used: we know
that this wildcard matches everything, so rechecking the match would be
useless at best, even if it were not actively harmful. And also skip
this call for "*" because calling Matches("*") always succeeds anyhow.

This also fixes the same bug in wxFind{First,Next}File() and any other
code using them such as wx{File,Dir}Ctrl.

Closes #23905.
This commit is contained in:
Vadim Zeitlin 2023-09-27 15:33:32 +02:00
parent df6366ff57
commit 3181f1988d
2 changed files with 20 additions and 1 deletions

View file

@ -20,6 +20,16 @@
#define DIRTEST_FOLDER wxString("dirTest_folder")
#define SEP wxFileName::GetPathSeparator()
// We can't use wxFileSelectorDefaultWildcardStr from wxCore here, so define
// our own.
const char WILDCARD_ALL[] =
#if defined(__WXMSW__)
"*.*"
#else // Unix/Mac
"*"
#endif
;
// ----------------------------------------------------------------------------
// test fixture
// ----------------------------------------------------------------------------
@ -145,6 +155,9 @@ TEST_CASE_METHOD(DirTestCase, "Dir::Traverse", "[dir]")
wxArrayString files;
CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files) == 4 );
// enum all files using an explicit wildcard
CHECK(wxDir::GetAllFiles(DIRTEST_FOLDER, &files, WILDCARD_ALL) == 4);
// enum all files according to the filter
CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "*.foo") == 1 );