Skip to content

Commit

Permalink
Fix unbalanced parenthesis in WKT parser. Retruns a Magic NULL inform…
Browse files Browse the repository at this point in the history
…ation.

Methods receiving this NULL must returns a NULL geometry.
  • Loading branch information
lbartoletti committed Aug 24, 2020
1 parent e433ada commit 653c1e0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/core/geometry/qgscircularstring.cpp
Expand Up @@ -317,6 +317,9 @@ bool QgsCircularString::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

setPoints( QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() ) ); setPoints( QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() ) );
return true; return true;
} }
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgscompoundcurve.cpp
Expand Up @@ -182,6 +182,9 @@ bool QgsCompoundCurve::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() ); QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() );


const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType ); const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType );
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -218,6 +218,9 @@ bool QgsCurvePolygon::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() ); QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() );


const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType ); const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType );
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -701,6 +701,9 @@ bool QgsGeometryCollection::fromCollectionWkt( const QString &wkt, const QVector
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() ); QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() );


const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defChildWkbType ); const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defChildWkbType );
Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -1300,7 +1300,9 @@ QPair<QgsWkbTypes::Type, QString> QgsGeometryUtils::wktReadBlock( const QString
{ {
QString wktParsed = wkt; QString wktParsed = wkt;
QString contents; QString contents;
if ( wkt.contains( QString( "EMPTY" ), Qt::CaseInsensitive ) ) if ( wktParsed.count( '(' ) != wktParsed.count( ')' ) ) // if unbalanced parenthesis will returns false
contents = QStringLiteral("NULL");
else if ( wkt.contains( QString( "EMPTY" ), Qt::CaseInsensitive ) )
{ {
QRegularExpression wktRegEx( QStringLiteral( "^\\s*(\\w+)\\s+(\\w+)\\s*$" ) ); QRegularExpression wktRegEx( QStringLiteral( "^\\s*(\\w+)\\s+(\\w+)\\s*$" ) );
wktRegEx.setPatternOptions( QRegularExpression::DotMatchesEverythingOption ); wktRegEx.setPatternOptions( QRegularExpression::DotMatchesEverythingOption );
Expand Down
5 changes: 4 additions & 1 deletion src/core/geometry/qgslinestring.cpp
Expand Up @@ -434,9 +434,12 @@ bool QgsLineString::fromWkt( const QString &wkt )
return false; return false;
mWkbType = parts.first; mWkbType = parts.first;


if ( parts.second == "EMPTY" ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

setPoints( QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() ) ); setPoints( QgsGeometryUtils::pointsFromWKT( parts.second, is3D(), isMeasure() ) );
return true; return true;
} }
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgspoint.cpp
Expand Up @@ -172,6 +172,9 @@ bool QgsPoint::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

QRegularExpression rx( QStringLiteral( "\\s" ) ); QRegularExpression rx( QStringLiteral( "\\s" ) );
QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts ); QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts );
if ( coordinates.size() < 2 ) if ( coordinates.size() < 2 )
Expand Down
3 changes: 3 additions & 0 deletions src/core/geometry/qgstriangle.cpp
Expand Up @@ -172,6 +172,9 @@ bool QgsTriangle::fromWkt( const QString &wkt )
if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 ) if ( parts.second.compare( QLatin1String( "EMPTY" ), Qt::CaseInsensitive ) == 0 )
return true; return true;


if ( parts.second.compare( QLatin1String( "NULL" ), Qt::CaseInsensitive ) == 0 )
return false;

QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() ); QString defaultChildWkbType = QStringLiteral( "LineString%1%2" ).arg( is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() );


const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType ); const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defaultChildWkbType );
Expand Down

0 comments on commit 653c1e0

Please sign in to comment.