Skip to content

Commit

Permalink
OGR decodeUri: be tolerant on layerName case
Browse files Browse the repository at this point in the history
Unreported issue: discovered in the QGIS-Documentation
test CI issue
https://travis-ci.org/github/qgis/QGIS-Documentation/builds/734917369#L679
  • Loading branch information
elpaso committed Oct 12, 2020
1 parent 1d2bb41 commit 9b99ecb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3473,9 +3473,9 @@ QVariantMap QgsOgrProviderMetadata::decodeUri( const QString &uri )

if ( path.contains( '|' ) )
{
const QRegularExpression geometryTypeRegex( QStringLiteral( "\\|geometrytype=([a-zA-Z0-9]*)" ) );
const QRegularExpression layerNameRegex( QStringLiteral( "\\|layername=([^|]*)" ) );
const QRegularExpression layerIdRegex( QStringLiteral( "\\|layerid=([^|]*)" ) );
const QRegularExpression geometryTypeRegex( QStringLiteral( "\\|geometrytype=([a-zA-Z0-9]*)" ), QRegularExpression::PatternOption::CaseInsensitiveOption );
const QRegularExpression layerNameRegex( QStringLiteral( "\\|layername=([^|]*)" ), QRegularExpression::PatternOption::CaseInsensitiveOption );
const QRegularExpression layerIdRegex( QStringLiteral( "\\|layerid=([^|]*)" ), QRegularExpression::PatternOption::CaseInsensitiveOption );
const QRegularExpression subsetRegex( QStringLiteral( "\\|subset=((?:.*[\r\n]*)*)\\Z" ) );
const QRegularExpression openOptionRegex( QStringLiteral( "\\|option:([^|]*)" ) );

Expand Down
15 changes: 15 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,26 @@ def testDecodeUri(self):
self.assertEqual(components["path"], filename)
self.assertEqual(components["layerName"], 'test')

uri = '{}|layerName=test'.format(filename)
components = registry.decodeUri('ogr', uri)
self.assertEqual(components["path"], filename)
self.assertEqual(components["layerName"], 'test')

uri = '{}|layerid=0'.format(filename)
components = registry.decodeUri('ogr', uri)
self.assertEqual(components["path"], filename)
self.assertEqual(components["layerId"], 0)

uri = '{}|layerId=0'.format(filename)
components = registry.decodeUri('ogr', uri)
self.assertEqual(components["path"], filename)
self.assertEqual(components["layerId"], 0)

uri = '{}|geometryType=POINT'.format(filename)
components = registry.decodeUri('ogr', uri)
self.assertEqual(components["path"], filename)
self.assertEqual(components["geometryType"], 'POINT')

def testEncodeUri(self):

filename = '/home/to/path/my_file.gpkg'
Expand Down

0 comments on commit 9b99ecb

Please sign in to comment.