Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Fix file parameters with filter string set which
includes a wildcard incorrectly flag formats not explicitly
listed as non-matching
  • Loading branch information
nyalldawson committed Aug 2, 2021
1 parent 2e6637c commit 729a748
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -3364,8 +3364,7 @@ bool QgsProcessingParameterFile::checkValueIsAcceptable( const QVariant &input,
}
else if ( !mFileFilter.isEmpty() )
{
const QString test = QgsFileUtils::addExtensionFromFilter( string, mFileFilter );
return test == string;
return QgsFileUtils::fileMatchesFilter( string, mFileFilter );
}
else
{
Expand Down
13 changes: 10 additions & 3 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -3775,8 +3775,8 @@ void TestQgsProcessing::parameterFile()
QVERIFY( dynamic_cast< QgsProcessingParameterFile *>( def.get() ) );

// with file filter
def.reset( new QgsProcessingParameterFile( "non_optional", QString(), QgsProcessingParameterFile::File, QStringLiteral( ".bmp" ), QString( "abc.bmp" ), false, QStringLiteral( "PNG Files (*.png)" ) ) );
QCOMPARE( def->fileFilter(), QStringLiteral( "PNG Files (*.png)" ) );
def.reset( new QgsProcessingParameterFile( "non_optional", QString(), QgsProcessingParameterFile::File, QStringLiteral( ".bmp" ), QString( "abc.bmp" ), false, QStringLiteral( "PNG Files (*.png *.PNG)" ) ) );
QCOMPARE( def->fileFilter(), QStringLiteral( "PNG Files (*.png *.PNG)" ) );
QVERIFY( def->extension().isEmpty() );
QVERIFY( def->checkValueIsAcceptable( "bricks.png" ) );
QVERIFY( def->checkValueIsAcceptable( "bricks.PNG" ) );
Expand All @@ -3789,7 +3789,7 @@ void TestQgsProcessing::parameterFile()
QCOMPARE( def->valueAsPythonString( QStringLiteral( "c:\\test\\new data\\test.dat" ), context ), QStringLiteral( "'c:\\\\test\\\\new data\\\\test.dat'" ) );

pythonCode = def->asPythonString();
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterFile('non_optional', '', behavior=QgsProcessingParameterFile.File, fileFilter='PNG Files (*.png)', defaultValue='abc.bmp')" ) );
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterFile('non_optional', '', behavior=QgsProcessingParameterFile.File, fileFilter='PNG Files (*.png *.PNG)', defaultValue='abc.bmp')" ) );

code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##non_optional=file abc.bmp" ) );
Expand All @@ -3814,6 +3814,13 @@ void TestQgsProcessing::parameterFile()
def.reset( dynamic_cast< QgsProcessingParameterFile *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
QVERIFY( dynamic_cast< QgsProcessingParameterFile *>( def.get() ) );

// with file filter with wildcards
def.reset( new QgsProcessingParameterFile( "non_optional", QString(), QgsProcessingParameterFile::File, QStringLiteral( ".bmp" ), QString( "abc.bmp" ), false, QStringLiteral( "PNG Files (*.png);;Other Files (*.*)" ) ) );
QVERIFY( def->checkValueIsAcceptable( "bricks.png" ) );
QVERIFY( def->checkValueIsAcceptable( "bricks.PNG" ) );
QVERIFY( def->checkValueIsAcceptable( "bricks.pcx" ) );
QVERIFY( def->checkValueIsAcceptable( "bricks.PCX" ) );

// optional
def.reset( new QgsProcessingParameterFile( "optional", QString(), QgsProcessingParameterFile::File, QString(), QString( "gef.bmp" ), true ) );
QVERIFY( def->checkValueIsAcceptable( false ) );
Expand Down

0 comments on commit 729a748

Please sign in to comment.