Skip to content
Permalink
Browse files

Catch exceptions in transform() expression function

(cherry-picked from 2a8333e)
  • Loading branch information
nyalldawson committed Sep 15, 2016
1 parent 8bb7284 commit cd27a0c2bf05c589754c6ce63e0b5916ab9184d1
Showing with 13 additions and 2 deletions.
  1. +12 −2 src/core/qgsexpression.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -50,6 +50,8 @@
#include "qgsexpressionprivate.h"
#include "qgsexpressionsorter.h"
#include "qgscrscache.h"
#include "qgsmessagelog.h"
#include "qgscsexception.h"

#if QT_VERSION < 0x050000
#include <qtextdocument.h>
@@ -2974,8 +2976,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();
}

@@ -748,6 +748,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" );

0 comments on commit cd27a0c

Please sign in to comment.
You can’t perform that action at this time.