Skip to content
Permalink
Browse files

[delimitedtext] Fix regression opening files with unicode characters

(fixes #41948)

(cherry picked from commit 7278ec8)
  • Loading branch information
nirvn authored and nyalldawson committed Mar 19, 2021
1 parent cf2b041 commit e760beecce35b763072b25932350c3aac7d0b5cc
@@ -1262,7 +1262,7 @@ QString QgsDelimitedTextProvider::description() const

QVariantMap QgsDelimitedTextProviderMetadata::decodeUri( const QString &uri )
{
const QUrl url( uri );
const QUrl url = QUrl::fromEncoded( uri.toLatin1() );
const QUrlQuery queryItems( url.query() );

QString subset;
@@ -1309,7 +1309,7 @@ QString QgsDelimitedTextProviderMetadata::encodeUri( const QVariantMap &parts )
queryItems.addQueryItem( QStringLiteral( "subset" ), parts.value( QStringLiteral( "subset" ) ).toString() );
url.setQuery( queryItems );

return url.toString();
return QString::fromLatin1( url.toEncoded() );
}

QgsDataProvider *QgsDelimitedTextProviderMetadata::createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
@@ -951,14 +951,23 @@ def testSpatialIndex(self):
vl.dataProvider().createSpatialIndex()
self.assertEqual(vl.hasSpatialIndex(), QgsFeatureSource.SpatialIndexPresent)

def testEncodeuri(self):
def testEncodeDecodeUri(self):
registry = QgsProviderRegistry.instance()

# URI decoding
filename = '/home/to/path/test.csv'
registry = QgsProviderRegistry.instance()
parts = {'path': filename}
uri = registry.encodeUri('delimitedtext', parts)
self.assertEqual(uri, 'file://' + filename)

# URI encoding / decoding with unicode characters
filename = '/höme/to/path/pöints.txt'
parts = {'path': filename}
uri = registry.encodeUri('delimitedtext', parts)
self.assertEqual(uri, 'file:///h%C3%B6me/to/path/p%C3%B6ints.txt')
parts = registry.decodeUri('delimitedtext', uri)
self.assertEqual(parts['path'], filename)

def testCREndOfLineAndWorkingBuffer(self):
# Test CSV file with \r (CR) endings
# Test also that the logic to refill the buffer works properly

0 comments on commit e760bee

Please sign in to comment.