Skip to content
Permalink
Browse files

[FEATURE] expression: align strpos behaviour with postgres

  • Loading branch information
jef-n committed Nov 19, 2015
1 parent f3a5dcc commit 2a557db39d9e0823658ea1ebbaf2e499ac5e1421
Showing with 3 additions and 3 deletions.
  1. +1 −1 src/core/qgsexpression.cpp
  2. +2 −2 tests/src/core/testqgsexpression.cpp
@@ -1012,7 +1012,7 @@ static QVariant fcnConcat( const QVariantList& values, const QgsExpressionContex
static QVariant fcnStrpos( const QVariantList& values, const QgsExpressionContext*, QgsExpression *parent )
{
QString string = getStringValue( values.at( 0 ), parent );
return string.indexOf( QRegExp( getStringValue( values.at( 1 ), parent ) ) );
return string.indexOf( QRegExp( getStringValue( values.at( 1 ), parent ) ) ) + 1;
}

static QVariant fcnRight( const QVariantList& values, const QgsExpressionContext*, QgsExpression *parent )
@@ -484,8 +484,8 @@ class TestQgsExpression: public QObject
QTest::newRow( "regexp_substr" ) << "regexp_substr('abc123','(\\\\d+)')" << false << QVariant( "123" );
QTest::newRow( "regexp_substr no hit" ) << "regexp_substr('abcdef','(\\\\d+)')" << false << QVariant( "" );
QTest::newRow( "regexp_substr invalid" ) << "regexp_substr('abc123','([[[')" << true << QVariant();
QTest::newRow( "strpos" ) << "strpos('Hello World','World')" << false << QVariant( 6 );
QTest::newRow( "strpos outside" ) << "strpos('Hello World','blah')" << false << QVariant( -1 );
QTest::newRow( "strpos" ) << "strpos('Hello World','World')" << false << QVariant( 7 );
QTest::newRow( "strpos outside" ) << "strpos('Hello World','blah')" << false << QVariant( 0 );
QTest::newRow( "left" ) << "left('Hello World',5)" << false << QVariant( "Hello" );
QTest::newRow( "right" ) << "right('Hello World', 5)" << false << QVariant( "World" );
QTest::newRow( "rpad" ) << "rpad('Hello', 10, 'x')" << false << QVariant( "Helloxxxxx" );

4 comments on commit 2a557db

@nyalldawson

This comment has been minimized.

Copy link
Contributor

@nyalldawson nyalldawson replied Nov 19, 2015

I agree with the new behaviour, but how will we handle older projects? A warning in the release notes?

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied Nov 19, 2015

If we had release notes - I'd say we should add it to the visual changelog (and I added a [FEATURE] to make the documentation team aware - and the lazy coder added a comment to the new issue qgis/QGIS-Documentation#679)

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn replied Nov 19, 2015

Who did the lazy coder script? Victim identified and contacted.
It would be nice to enhance it so it catches deprecated annotations and puts it into the "release notes".

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Nov 20, 2015

@jef-n , that was quick, thanks. BTW, the strpos function help text needs updating too.

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