Skip to content

Commit

Permalink
Use a better regex for removing invalid characters from filenames
Browse files Browse the repository at this point in the history
Fixes atlas exports remove international characters from filenames

Fixes #18291

(cherry-picked from 8543a9)
  • Loading branch information
nyalldawson committed Mar 6, 2018
1 parent d8734e3 commit d43db07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsfileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsfileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit d43db07

Please sign in to comment.