#14404 Guard against whitespace in AppEnum serialization text and fix affected enums

This commit is contained in:
Magne Sjaastad authored and GitHub committed 2026-07-30 08:41:27 +02:00
1 parent c91e5fa9a7
commit 4c39ce3e6c
8 files changed
+42 -20

No files matched your search

+7 -7
View File
@@ -46,13 +46,13 @@ namespace caf
template <>
void cvf::StructGridInterface::FaceEnum::setUp()
{
addItem( cvf::StructGridInterface::POS_I, "POS I", "" );
addItem( cvf::StructGridInterface::NEG_I, "NEG I", "" );
addItem( cvf::StructGridInterface::POS_J, "POS J", "" );
addItem( cvf::StructGridInterface::NEG_J, "NEG J", "" );
addItem( cvf::StructGridInterface::POS_K, "POS K", "" );
addItem( cvf::StructGridInterface::NEG_K, "NEG K", "" );
addItem( cvf::StructGridInterface::NO_FACE, "UnDef", "" );
addItem( cvf::StructGridInterface::POS_I, "POS_I", "POS I" );
addItem( cvf::StructGridInterface::NEG_I, "NEG_I", "NEG I" );
addItem( cvf::StructGridInterface::POS_J, "POS_J", "POS J" );
addItem( cvf::StructGridInterface::NEG_J, "NEG_J", "NEG J" );
addItem( cvf::StructGridInterface::POS_K, "POS_K", "POS K" );
addItem( cvf::StructGridInterface::NEG_K, "NEG_K", "NEG K" );
addItem( cvf::StructGridInterface::NO_FACE, "UNDEF", "UnDef" );
}
} // namespace caf
@@ -43,6 +43,8 @@
#include "cafAssert.h"
#include <algorithm>
namespace caf
{
@@ -57,11 +59,25 @@ bool AppEnumMapperBase::EnumData::isMatching( const QString& text ) const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace
{
bool containsWhitespace( const QString& text )
{
return std::any_of( text.begin(), text.end(), []( const QChar& c ) { return c.isSpace(); } );
}
} // namespace
void AppEnumMapperBase::addItem( int enumVal, const QString& text, QString uiText, const QStringList& aliases )
{
// The serialization text is read back from XML one whitespace-delimited token at a time, so texts and
// aliases with embedded whitespace would silently be replaced by the default enum value on import
// https://github.com/OPM/ResInsight/issues/14404
CAF_ASSERT( !containsWhitespace( text.trimmed() ) );
// Make sure the alias text is unique for enum
for ( const auto& alias : aliases )
{
CAF_ASSERT( !containsWhitespace( alias ) );
for ( const auto& enumData : m_mapping )
{
CAF_ASSERT( !enumData.isMatching( alias ) );