mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 09:00:14 -06:00
#14404 Guard against whitespace in AppEnum serialization text and fix affected enums
This commit is contained in:
1 parent
c91e5fa9a7
commit
4c39ce3e6c
8 files changed
+42
-20
No files matched your search
@@ -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 ) );
|
||||
|
||||
Reference in new issue
Block a user