Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a few more LIKE expression tests, fix regexp escaping
  • Loading branch information
nirvn committed Jul 14, 2021
1 parent 86fa201 commit 9769b69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpressionnodeimpl.cpp
Expand Up @@ -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 _
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 9769b69

Please sign in to comment.