From a612fb690bc08bf1215755772a0e04a447a541a6 Mon Sep 17 00:00:00 2001 From: Jeff Young <jeff@rokeby.ie> Date: Sat, 7 Sep 2019 03:13:08 +0100 Subject: [PATCH] Cherry pick of line-ending-safety fix from 5.1. Fixes: lp:1842943 * https://bugs.launchpad.net/kicad/+bug/1842943 --- common/gestfich.cpp | 7 ++++++- common/string.cpp | 6 +++++- include/kicad_string.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/gestfich.cpp b/common/gestfich.cpp index 593d318186..058cc57761 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -337,7 +337,12 @@ bool doPrintFile( const wxString& file, bool aDryRun ) } #endif - DisplayError( NULL, wxString::Format( _( "Cannot print '%s'.\n\nUnknown filetype." ), file ) ); + if( !aDryRun ) + { + DisplayError( nullptr, wxString::Format( _( "Cannot print '%s'.\n\nUnknown filetype." ), + file ) ); + } + return false; } diff --git a/common/string.cpp b/common/string.cpp index 001656c920..48ab542334 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -246,8 +246,12 @@ int ReadDelimitedText( char* aDest, const char* aSource, int aDestSize ) } -std::string EscapedUTF8( const wxString& aString ) +std::string EscapedUTF8( wxString aString ) { + // No new-lines allowed in quoted strings + aString.Replace( "\r\n", "\r" ); + aString.Replace( "\n", "\r" ); + std::string utf8 = TO_UTF8( aString ); std::string ret; diff --git a/include/kicad_string.h b/include/kicad_string.h index e0c4e53164..71bce02119 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -87,7 +87,7 @@ int ReadDelimitedText( wxString* aDest, const char* aSource ); * @param aString is the input string to convert. * @return std::string - the escaped input text, without the wrapping double quotes. */ -std::string EscapedUTF8( const wxString& aString ); +std::string EscapedUTF8( wxString aString ); /** * Return a new wxString escaped for embedding in HTML.