Skip to content
Permalink
Browse files

Use a better regex for removing invalid characters from filenames

Fixes atlas exports remove international characters from filenames

Fixes #18291

(cherry-picked from 8543a9)
  • Loading branch information
nyalldawson committed Mar 3, 2018
1 parent d8734e3 commit d43db07d3fc998ce504601c8bcb4df1feee495f1
Showing with 3 additions and 3 deletions.
  1. +1 −1 src/core/qgsfileutils.cpp
  2. +2 −2 tests/src/python/test_qgsfileutils.py
@@ -86,7 +86,7 @@ QString QgsFileUtils::addExtensionFromFilter( const QString &fileName, const QSt

QString QgsFileUtils::stringToSafeFilename( const QString &string )
{
QRegularExpression rx( "[^\\w\\-. ]" );
QRegularExpression rx( "[/\\\\\\?%\\*\\:\\|\"<>]" );
QString s = string;
s.replace( rx, QStringLiteral( "_" ) );
return s;
@@ -58,8 +58,8 @@ def testAddExtensionFromFilter(self):
def testStringToSafeFilename(self):
self.assertEqual(QgsFileUtils.stringToSafeFilename('my FiLe v2.0_new.tif'), 'my FiLe v2.0_new.tif')
self.assertEqual(
QgsFileUtils.stringToSafeFilename('rendered map_final? rev (12-03-1017)_real@#$&*#%&*$!!@$%^&(*(.tif'),
'rendered map_final_ rev _12-03-1017__real____________________.tif')
QgsFileUtils.stringToSafeFilename('rendered map_final? rev (12-03-1017)_real/\\?%*:|"<>.tif'),
'rendered map_final_ rev (12-03-1017)_real__________.tif')


if __name__ == '__main__':

0 comments on commit d43db07

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