diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp index d5ef7a0416f..2fa39065f9b 100644 --- a/src/core/qgsofflineediting.cpp +++ b/src/core/qgsofflineediting.cpp @@ -251,7 +251,8 @@ void QgsOfflineEditing::synchronize() QString remoteProvider = layer->customProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, "" ).toString(); QString remoteName = layer->name(); QString remoteNameSuffix = layer->customProperty( CUSTOM_PROPERTY_LAYERNAME_SUFFIX, " (offline)" ).toString(); - remoteName.remove( remoteNameSuffix ); + if ( remoteName.endsWith( remoteNameSuffix ) ) + remoteName.chop( remoteNameSuffix.size() ); const QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() }; QgsVectorLayer *remoteLayer = new QgsVectorLayer( remoteSource, remoteName, remoteProvider, options ); if ( remoteLayer->isValid() ) diff --git a/tests/src/core/testqgsofflineediting.cpp b/tests/src/core/testqgsofflineediting.cpp index a57c1021711..74bc37f8e98 100644 --- a/tests/src/core/testqgsofflineediting.cpp +++ b/tests/src/core/testqgsofflineediting.cpp @@ -121,9 +121,10 @@ void TestQgsOfflineEditing::createSpatialiteAndSynchronizeBack_data() QTest::addColumn( "suffix_input" ); QTest::addColumn( "suffix_result" ); - QTest::newRow( "no suffix" ) << QString( "no suffix" ) << QStringLiteral( " (offline)" ); + QTest::newRow( "no suffix" ) << QString( "no suffix" ) << QStringLiteral( " (offline)" ); //default value expected QTest::newRow( "null suffix" ) << QString() << QString(); QTest::newRow( "empty suffix" ) << QStringLiteral( "" ) << QStringLiteral( "" ); + QTest::newRow( "part of name suffix" ) << QStringLiteral( "point" ) << QStringLiteral( "point" ); QTest::newRow( "another suffix" ) << QStringLiteral( "another suffix" ) << QStringLiteral( "another suffix" ); } @@ -132,9 +133,10 @@ void TestQgsOfflineEditing::createGeopackageAndSynchronizeBack_data() QTest::addColumn( "suffix_input" ); QTest::addColumn( "suffix_result" ); - QTest::newRow( "no suffix" ) << QStringLiteral( "no suffix" ) << QStringLiteral( " (offline)" ); + QTest::newRow( "no suffix" ) << QStringLiteral( "no suffix" ) << QStringLiteral( " (offline)" ); //default value expected QTest::newRow( "null suffix" ) << QString() << QString(); QTest::newRow( "empty suffix" ) << QStringLiteral( "" ) << QStringLiteral( "" ); + QTest::newRow( "part of name suffix" ) << QStringLiteral( "point" ) << QStringLiteral( "point" ); QTest::newRow( "another suffix" ) << QStringLiteral( "another suffix" ) << QStringLiteral( "another suffix" ); }