Skip to content

Commit

Permalink
Fix raster calculator invalid expressions
Browse files Browse the repository at this point in the history
Tell the user that is invalid instead of
silently ignoring undefined functions.

Fixes #29824
  • Loading branch information
elpaso committed May 27, 2019
1 parent b545979 commit 892ccfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/analysis/raster/qgsrastercalclexer.ll
Expand Up @@ -36,6 +36,7 @@
#ifdef _MSC_VER
#define YY_NO_UNISTD_H
#endif

%}

white [ \t\r\n]+
Expand Down Expand Up @@ -80,8 +81,12 @@ raster_band_ref_quoted \"(\\.|[^"])*\"
{raster_band_ref_quoted} { return RASTER_BAND_REF; }
{white} /* skip blanks and tabs */
[a-z][a-z0-9_]* { return yytext[0]; } /* other unknown tokens */
%%
void set_raster_input_buffer(const char* buffer)
{
raster_scan_string(buffer);
Expand Down
14 changes: 14 additions & 0 deletions tests/src/analysis/testqgsrastercalculator.cpp
Expand Up @@ -573,6 +573,20 @@ void TestQgsRasterCalculator::findNodes()
QCOMPARE( _test( QStringLiteral( "2 + 3" ), QgsRasterCalcNode::Type::tNumber ).length(), 2 );
QCOMPARE( _test( QStringLiteral( "2 + 3" ), QgsRasterCalcNode::Type::tOperator ).length(), 1 );

// Test parser with valid and invalid expressions
QString errorString;
const QgsRasterCalcNode *node { QgsRasterCalcNode::parseRasterCalcString( QString( ), errorString ) };
QVERIFY( ! node );
QVERIFY( ! errorString.isEmpty() );
errorString = QString();
node = QgsRasterCalcNode::parseRasterCalcString( QStringLiteral( "log10(2)" ), errorString );
QVERIFY( node );
QVERIFY( errorString.isEmpty() );
errorString = QString();
node = QgsRasterCalcNode::parseRasterCalcString( QStringLiteral( "not_a_function(2)" ), errorString );
QVERIFY( ! node );
QVERIFY( ! errorString.isEmpty() );

}

void TestQgsRasterCalculator::testRasterEntries()
Expand Down

0 comments on commit 892ccfe

Please sign in to comment.