Skip to content
Permalink
Browse files
Add a few more LIKE expression tests, fix regexp escaping
  • Loading branch information
nirvn committed Jul 14, 2021
1 parent 86fa201 commit 9769b69ff92ddf9cde92b87bcb16ff22565fe228
Showing with 4 additions and 1 deletion.
  1. +1 −1 src/core/expression/qgsexpressionnodeimpl.cpp
  2. +3 −0 tests/src/core/testqgsexpression.cpp
@@ -536,7 +536,7 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
if ( mOp == boLike || mOp == boILike || mOp == boNotLike || mOp == boNotILike ) // change from LIKE syntax to regexp
{
// recreate QRegExp::escape function behavior
const thread_local QRegularExpression escapeRx( QStringLiteral( "([^\\\\])([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}])" ) );
const thread_local QRegularExpression escapeRx( QStringLiteral( "([^\\\\]|^)([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}])" ) );
QString esc_regexp = regexp;
esc_regexp.replace( escapeRx, QStringLiteral( "\\1\\\\2" ) );
// manage escape % and _
@@ -765,7 +765,10 @@ class TestQgsExpression: public QObject
QTest::newRow( "like 2" ) << "'hello' like '_el%'" << false << QVariant( 1 );
QTest::newRow( "like 3" ) << "'hello' like 'lo'" << false << QVariant( 0 );
QTest::newRow( "like 4" ) << "'hello' like '%LO'" << false << QVariant( 0 );
QTest::newRow( "like 5" ) << "'QGIS' like '%G%'" << false << QVariant( 1 );
QTest::newRow( "like 6" ) << "'[testing]' like '[testing%'" << false << QVariant( 1 );
QTest::newRow( "ilike" ) << "'hello' ilike '%LO'" << false << QVariant( 1 );
QTest::newRow( "ilike with dot" ) << "'QGIS .123' ilike 'qgis .123'" << false << QVariant( 1 );
// the \\\\ is like \\ in the interface
QTest::newRow( "like escape 1" ) << "'1%' like '1\\\\%'" << false << QVariant( 1 );
QTest::newRow( "like escape 2" ) << "'1_' like '1\\\\%'" << false << QVariant( 0 );

0 comments on commit 9769b69

Please sign in to comment.