Allow spaces in net names by default

The NETNAME_VALIDATOR was inconsistent: eeschema dialogs explicitly
allowed spaces but PCBNew net inspector used the default (no spaces).
This caused confusion where net names could be created with spaces in
eeschema but the net inspector rejected them.

Changed the default m_allowSpaces from false to true to make behavior
consistent across all validators. Added unit tests to verify the
behavior.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9258
This commit is contained in:
Seth Hillbrand
2026-01-08 13:32:13 -08:00
parent ef98ecea70
commit 32739d383c
3 changed files with 91 additions and 1 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ void ENV_VAR_NAME_VALIDATOR::OnTextChanged( wxCommandEvent& event )
NETNAME_VALIDATOR::NETNAME_VALIDATOR( wxString *aVal ) :
wxTextValidator(),
m_allowSpaces( false )
m_allowSpaces( true )
{
}
+2
View File
@@ -92,6 +92,8 @@ set( QA_COMMON_SRCS
view/test_zoom_controller.cpp
test_netname_validator.cpp
# GAL tests
test_gal_xor_mode.cpp
@@ -0,0 +1,88 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The 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 as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <validators.h>
BOOST_AUTO_TEST_SUITE( NetnameValidator )
struct ValidatorFixture
{
ValidatorFixture() : m_validatorAllowSpaces( true ), m_validatorNoSpaces( false )
{
}
NETNAME_VALIDATOR m_validatorDefault;
NETNAME_VALIDATOR m_validatorAllowSpaces;
NETNAME_VALIDATOR m_validatorNoSpaces;
};
BOOST_FIXTURE_TEST_CASE( DefaultValidatorAllowsSpaces, ValidatorFixture )
{
// Default validator should allow spaces (issue #9258)
BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Single_word" ) ).IsEmpty() );
BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net name with multiple spaces" ) ).IsEmpty() );
}
BOOST_FIXTURE_TEST_CASE( ValidatorAllowsSpacesWhenConfigured, ValidatorFixture )
{
// Validator with allowSpaces=true should allow spaces
BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() );
}
BOOST_FIXTURE_TEST_CASE( ValidatorRejectsSpacesWhenConfigured, ValidatorFixture )
{
// Validator with allowSpaces=false should reject spaces
BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net with spaces" ) ).IsEmpty() );
BOOST_CHECK( m_validatorNoSpaces.IsValid( wxS( "Single_word" ) ).IsEmpty() );
}
BOOST_FIXTURE_TEST_CASE( ValidatorRejectsControlCharacters, ValidatorFixture )
{
// All validators should reject CR and LF
BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
BOOST_CHECK( !m_validatorDefault.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
BOOST_CHECK( !m_validatorAllowSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\nname" ) ).IsEmpty() );
BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\rname" ) ).IsEmpty() );
}
BOOST_FIXTURE_TEST_CASE( ValidatorRejectsTabsWhenSpacesDisallowed, ValidatorFixture )
{
// Validator with allowSpaces=false should reject tabs
BOOST_CHECK( !m_validatorNoSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
// Default and allowSpaces=true should accept tabs (they're treated like spaces)
BOOST_CHECK( m_validatorDefault.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
BOOST_CHECK( m_validatorAllowSpaces.IsValid( wxS( "Net\twith\ttabs" ) ).IsEmpty() );
}
BOOST_AUTO_TEST_SUITE_END()