From b931883876c2a09f6e587c2b262df662a5bf2fa8 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 18 Sep 2021 18:17:54 +0200 Subject: [PATCH] PANEL_FP_PROPERTIES_3D_MODEL: fix an issue when trying to edit a filename (MSW specific). On Windows, FILENAME_RESOLVER::ValidateFileName() always returned a illegal filename test, because the separators ('/' and '\') are in list of illegal chars in filenames on MSW. --- common/filename_resolver.cpp | 13 ++++++++++++- pcbnew/dialogs/panel_fp_properties_3d_model.cpp | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common/filename_resolver.cpp b/common/filename_resolver.cpp index 4f84f02f3c..3920879263 100644 --- a/common/filename_resolver.cpp +++ b/common/filename_resolver.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2020 Cirilo Bernardo + * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -1013,7 +1014,17 @@ bool FILENAME_RESOLVER::ValidateFileName( const wxString& aFileName, bool& hasAl } - if( wxString::npos != lpath.find_first_of( wxFileName::GetForbiddenChars() ) ) + // Test for forbidden chars in filenames. Should be wxFileName::GetForbiddenChars() + // On MSW, the list returned by wxFileName::GetForbiddenChars() contains separators + // '\'and '/' used here because lpath is a full path (after last ':'). + // So remove separators + wxString lpath_no_sep = lpath; +#ifdef __WINDOWS__ + lpath_no_sep.Replace( "/", " " ); + lpath_no_sep.Replace( "\\", " " ); +#endif + + if( wxString::npos != lpath_no_sep.find_first_of( wxFileName::GetForbiddenChars() ) ) return false; return true; diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp index c1ac16aa8f..3394ce511f 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp @@ -218,7 +218,11 @@ void PANEL_FP_PROPERTIES_3D_MODEL::On3DModelCellChanged( wxGridEvent& aEvent ) // The user is warned about failed validation through the updateValidateStatus call below if( filename.empty() || !res->ValidateFileName( filename, hasAlias ) ) + { + wxMessageBox( _( "Error: illegal or empty filename." ) ); aEvent.Veto(); + return; + } // if the user has specified an alias in the name then prepend ':' if( hasAlias )