From 0403437ad04ea845a16df632eb5b7635bcb2f3db Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 20 May 2019 14:43:47 -0400 Subject: [PATCH] Eeschema: replace invalid characters when converting from text to label. Fixes lp:1829664 https://bugs.launchpad.net/kicad/+bug/1829664 --- eeschema/edit_label.cpp | 23 +++++++++++++---------- eeschema/sch_edit_frame.h | 4 ++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index 1dae89db0c..2c94a47919 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -124,14 +124,6 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType ) } -/* - * OnConvertTextType is a command event handler to change a text type to another one. - * The new text, label, hierarchical label, or global label is created from the old text - * The old text is deleted. - * A tricky case is when the 'old" text is being edited (i.e. moving) - * because we must create a new text, and prepare the undo/redo command data for this - * change and the current move/edit command - */ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); @@ -169,7 +161,18 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) SCH_TEXT* newtext = nullptr; const wxPoint &position = text->GetPosition(); - const wxString &txt = text->GetText(); + wxString txt = text->GetText(); + + // There can be characters in a SCH_TEXT object that can break labels so we have to + // fix them here. + if( text->Type() == SCH_TEXT_T ) + { + txt.Replace( "\n", "_" ); + txt.Replace( "\r", "_" ); + txt.Replace( "\t", "_" ); + txt.Replace( " ", "_" ); + txt.Replace( "/", "_" ); + } switch( type ) { diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 9445db3cbb..20154c8807 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -985,6 +985,10 @@ private: * * The new text, label, hierarchical label, or global label is created from the old text * and the old text object is deleted. + * + * A tricky case is when the 'old" text is being edited (i.e. moving) because we must + * create a new text, and prepare the undo/redo command data for this change and the + * current move/edit command */ void OnConvertTextType( wxCommandEvent& aEvent );