Skip to content

Commit

Permalink
Assert if any of the layer ids contains a comma
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jan 12, 2021
1 parent 31db15d commit f56f42e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/qgspolymorphicrelation.cpp
Expand Up @@ -66,7 +66,6 @@ QgsPolymorphicRelation QgsPolymorphicRelation::createFromXml( const QDomNode &no
QString referencedLayerExpression = elem.attribute( QStringLiteral( "referencedLayerExpression" ) );
QString id = elem.attribute( QStringLiteral( "id" ) );
QString name = elem.attribute( QStringLiteral( "name" ) );
// we UNsafely assume there are no "," is the relation ids
const QStringList referencedLayerIds = elem.attribute( QStringLiteral( "referencedLayerIds" ) ).split( "," );

QMap<QString, QgsMapLayer *> mapLayers = relationContext.project()->mapLayers();
Expand Down Expand Up @@ -105,6 +104,10 @@ void QgsPolymorphicRelation::writeXml( QDomNode &node, QDomDocument &doc ) const
elem.setAttribute( QStringLiteral( "referencedLayerExpression" ), d->mReferencedLayerExpression );
elem.setAttribute( QStringLiteral( "referencedLayerIds" ), d->mReferencedLayerIds.join( "," ) );

// note that a layer id can store a comma in theory. Luckyly, this is not easy to achieve, e.g. you need to modify the .qgs file manually
for ( const QString &layerId : qgis::as_const( d->mReferencedLayerIds ) )
Q_ASSERT( ! layerId.contains( "," ) );

for ( const QgsRelation::FieldPair &pair : qgis::as_const( d->mFieldPairs ) )
{
QDomElement referenceElem = doc.createElement( QStringLiteral( "fieldRef" ) );
Expand Down

0 comments on commit f56f42e

Please sign in to comment.