| 362 | } |
| 363 | |
| 364 | void ExportFilePanel::ValidateAndFixExt() |
| 365 | { |
| 366 | if(mSelectedPlugin == nullptr) |
| 367 | return; |
| 368 | |
| 369 | const auto formatInfo = mSelectedPlugin->GetFormatInfo(mSelectedFormatIndex); |
| 370 | if(formatInfo.extensions.empty()) |
| 371 | return; |
| 372 | |
| 373 | wxFileName filename; |
| 374 | filename.SetFullName(mFullName->GetValue()); |
| 375 | const auto desiredExt = filename.GetExt().Trim(); |
| 376 | |
| 377 | //See https://github.com/audacity/audacity/issues/5823 |
| 378 | //check if extension is valid, i.e. does not contain whitespace characters. |
| 379 | //Otherwise everything after '.'(if present) is considered to be a part of name. |
| 380 | if(wxRegEx{R"(^[^ ]+$)"}.Matches(desiredExt)) |
| 381 | { |
| 382 | auto it = std::find_if( |
| 383 | formatInfo.extensions.begin(), |
| 384 | formatInfo.extensions.end(), |
| 385 | // if typed extension uses different case (e.g. MP3 instead of mp3) |
| 386 | // we'll reset the file extension to one provided by FormatInfo |
| 387 | [&](const auto& ext) { return desiredExt.IsSameAs(ext, false); }); |
| 388 | |
| 389 | if(it == formatInfo.extensions.end()) |
| 390 | it = formatInfo.extensions.begin(); |
| 391 | |
| 392 | if(!it->empty() && !it->IsSameAs(filename.GetExt())) |
| 393 | { |
| 394 | filename.SetExt(*it); |
| 395 | mFullName->SetValue(filename.GetFullName()); |
| 396 | } |
| 397 | } |
| 398 | else if(!formatInfo.extensions.front().empty()) |
| 399 | { |
| 400 | auto fullname = filename.GetFullName(); |
| 401 | if(!fullname.EndsWith(".")) |
| 402 | fullname.Append("."); |
| 403 | fullname.Append(formatInfo.extensions.front()); |
| 404 | filename.SetFullName(fullname); |
| 405 | mFullName->SetValue(filename.GetFullName()); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | void ExportFilePanel::OnFullNameFocusKill(wxFocusEvent& event) |
| 410 | { |