PCBNew: Quotes in Text objects cause text to get truncated
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
KiCad |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
PCBnew Version: 2011-01-22 BZR 2754
OS: Windows 7
Just a nit: If the user puts double quotes in a Text object they place on a board in PCBnew, the quotes and any text after them do not get saved.
Repro steps:
1) Run PCBnew and edit a board
2) Click the Place >> Text menu item (or click on the corresponding toolbar button)
3) Click anywhere on the board
4) Enter "Quoted "text" causes problems" (WITHOUT the outer double quotes but WITH the inner double quotes)
5) Save the board and reopen it
Expected behavior: The text should appear as you entered it.
Actual behavior: You just see the word "Quoted." The rest of the text has been lost. If you edit the text item, you will see that the text with the quotes and anything after it was truncated at file save.
I ran across this when I was leaving a placeholder for a mini-protoboard on a board I was creating. I was trying to put a "Place a 1.4" x 1.6" protoboard here" message on the silkscreen layer.
Workaround: If you use two single quotes (which look a heck of a lot like one set of double quotes) everything works fine.
Note: This bug does not occur for the Text item in EESchema.
Since this is all pretty fresh in my old head, having just solved the issues
like this for the s-expression support, I stepped up and committed a partial
solution for the old board format too. The strategy used can be applied in
many places, to fix this in a general and comprehensive way.
The strategy involves "escaping" of double quotes with a preceding \
character, and doubling up the \ byte when present alone. (The s-expression
support went further, and that was to translate CR NL bytes to \r and \r two
byte pairs, but that was not done here.)
1) ReadDelimitedText() was revised to handle the escaping.
2) std::string EscapedUTF8( const wxString& aString ) was written to
complement the revised ReadDelimitedText() function for writing out these
strings. See line 166 of class_pcb_text.cpp as an example of what needs to
be done everywhere that ReadDelimitedText() is used as the inverse for reading.
More work needs to be done planting EscapedUTF8() in many places. The
reported bug's usage of " was only one of many potential problems handling
double quotes, but they can all be fixed simply by using EscapedUTF8().
There is a minor vulnerability in making the transition, if you have a \
byte in your board file already, since it is not currently doubled up, when
we read it we will basically skip it now, although I suppose a minor
enhancement would be to only skip it if the next byte is either " or \.
Dick