Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Catch exceptions in transform() expression function
(cherry-picked from 2a8333e)
  • Loading branch information
nyalldawson committed Sep 15, 2016
1 parent 53a7010 commit 0a0544e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/qgsexpression.cpp
Expand Up @@ -49,6 +49,8 @@
#include "qgscurvepolygonv2.h"
#include "qgsexpressionprivate.h"
#include "qgsexpressionsorter.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

#if QT_VERSION < 0x050000
#include <qtextdocument.h>
Expand Down Expand Up @@ -2634,8 +2636,16 @@ static QVariant fcnTransformGeometry( const QVariantList& values, const QgsExpre
return QVariant::fromValue( fGeom );

QgsCoordinateTransform t( s, d );
if ( fGeom.transform( t ) == 0 )
return QVariant::fromValue( fGeom );
try
{
if ( fGeom.transform( t ) == 0 )
return QVariant::fromValue( fGeom );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught in transform() function: %1" ).arg( cse.what() ) );
return QVariant();
}
return QVariant();
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -614,6 +614,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "shortest_line geom" ) << "geom_to_wkt(shortest_line( geom_from_wkt('LineString( 1 1, 5 1, 5 5 )'),geom_from_wkt('Point( 6 3 )')))" << false << QVariant( "LineString (5 3, 6 3)" );
QTest::newRow( "shortest_line not geom" ) << "shortest_line('g','a')" << true << QVariant();
QTest::newRow( "shortest_line null" ) << "shortest_line(NULL,NULL)" << false << QVariant();
QTest::newRow( "transform invalid" ) << "transform(make_point(0,0),'EPSG:4326','EPSG:28356')" << false << QVariant();

// string functions
QTest::newRow( "lower" ) << "lower('HeLLo')" << false << QVariant( "hello" );
Expand Down

0 comments on commit 0a0544e

Please sign in to comment.