Skip to content

Commit

Permalink
new string escaping logic for python
Browse files Browse the repository at this point in the history
  • Loading branch information
Koyaani authored and nyalldawson committed Sep 24, 2021
1 parent 968db20 commit e873dd3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -704,9 +704,16 @@ QString QgsProcessingUtils::stringToPythonLiteral( const QString &string )
s.replace( '\n', QLatin1String( "\\n" ) );
s.replace( '\r', QLatin1String( "\\r" ) );
s.replace( '\t', QLatin1String( "\\t" ) );
s.replace( '"', QLatin1String( "\\\"" ) );
s.replace( '\'', QLatin1String( "\\\'" ) );
s = s.prepend( '\'' ).append( '\'' );

if ( s.contains( '\'' ) && !s.contains( '\"' ) )
{
s = s.prepend( '"' ).append( '"' );
}
else
{
s.replace( '\'', QLatin1String( "\\\'" ) );
s = s.prepend( '\'' ).append( '\'' );
}
return s;
}

Expand Down

0 comments on commit e873dd3

Please sign in to comment.