mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Use a better regex for removing invalid characters from filenames
Fixes atlas exports remove international characters from filenames Fixes #18291
This commit is contained in:
parent
847683b500
commit
8543a91264
@ -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 @@ class TestQgsFileUtils(unittest.TestCase):
|
||||
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__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user