Skip to content

Commit

Permalink
[ogr] Fix decodeUri unable to handle newline characters in the subset…
Browse files Browse the repository at this point in the history
… string
  • Loading branch information
nirvn authored and nyalldawson committed Oct 1, 2020
1 parent 80f00f8 commit 7af60f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -3433,7 +3433,7 @@ QVariantMap QgsOgrProviderMetadata::decodeUri( const QString &uri )
const QRegularExpression geometryTypeRegex( QStringLiteral( "\\|geometrytype=([a-zA-Z0-9]*)" ) );
const QRegularExpression layerNameRegex( QStringLiteral( "\\|layername=([^|]*)" ) );
const QRegularExpression layerIdRegex( QStringLiteral( "\\|layerid=([^|]*)" ) );
const QRegularExpression subsetRegex( QStringLiteral( "\\|subset=(.*)$" ) );
const QRegularExpression subsetRegex( QStringLiteral( "\\|subset=((?:.*[\r\n]*)*)\\Z" ) );


// we first try to split off the geometry type component, if that's present. That's a known quantity which
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsogrprovider.cpp
Expand Up @@ -220,12 +220,12 @@ void TestQgsOgrProvider::decodeUri()
QVERIFY( !parts.value( QStringLiteral( "layerId" ) ).isValid() );
QCOMPARE( parts.value( QStringLiteral( "subset" ) ).toString(), QString( "A IN (3,4,5) or \"b\"='x|layerid'" ) );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "/path/to/a/geopackage.gpkg" ) );
parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "/path/to/a/geopackage.gpkg|layerid=4|subset=A IN (3,4,5) or \"b\"='x|layerid'|geometrytype=polygonz|layername=my_subset" ) );
parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), QStringLiteral( "/path/to/a/geopackage.gpkg|layerid=4|subset=A IN (3,4,5) or \n\"b\"='x|layerid'|geometrytype=polygonz|layername=my_subset" ) );
QCOMPARE( parts.size(), 5 );
QCOMPARE( parts.value( QStringLiteral( "layerName" ) ).toString(), QString( "my_subset" ) );
QCOMPARE( parts.value( QStringLiteral( "geometryType" ) ).toString(), QString( "polygonz" ) );
QVERIFY( !parts.value( QStringLiteral( "layerId" ) ).isValid() );
QCOMPARE( parts.value( QStringLiteral( "subset" ) ).toString(), QString( "A IN (3,4,5) or \"b\"='x|layerid'" ) );
QCOMPARE( parts.value( QStringLiteral( "subset" ) ).toString(), QString( "A IN (3,4,5) or \n\"b\"='x|layerid'" ) );
QCOMPARE( parts.value( QStringLiteral( "path" ) ).toString(), QString( "/path/to/a/geopackage.gpkg" ) );
}

Expand Down

0 comments on commit 7af60f6

Please sign in to comment.