PCBNew: Quotes in Text objects cause text to get truncated

Bug #725756 reported by PhilHut
6
This bug affects 1 person
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.

Related branches

Revision history for this message
Dick Hollenbeck (dickelbeck) wrote : Re: [Bug 725756] [NEW] PCBNew: Quotes in Text objects cause text to get truncated

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

Revision history for this message
Dick Hollenbeck (dickelbeck) wrote : Re: [Bug 725756] [NEW] PCBNew: Quotes in Text objects cause text to get truncated

On 02/26/2011 11:54 PM, Dick Hollenbeck wrote:
> 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 \.

Made that enhancement.

And I think this means it is safe to immediately use the new code everywhere
in the current/old data files.

Dick

Revision history for this message
Dick Hollenbeck (dickelbeck) wrote :

When expanding usage of EscapedUTF8(), some issues to keep in mind are:

1) Can the reading code be made string "line offset/position" independent, now that escape sequences can expand the length of a field. ReadDelimitedText() returns the number of bytes consumed, so of course yes, but it needs to be looked at now more closely, rather than just assuming that a certain field will be at a certain fixed offset. Instead, an accumulation of the return values from ReadDelimitedText() have to be used to establish the next field's offset.

2) EscapedUTF8() could easily be changed to add the wrapping double quotes and thereby simply the fprintf() format string that is used everywhere, by makeing \"%s\" be simply %s. This is a pending design decision, and is a reason why I did not install EscapedUTF8() everywhere just yet.

Opinions welcome. I am done working on this for now. Sort of feel like anything we do is only temporaty anyway, pending an eventual migration to s-expressions, where I feel the issue of embedded quotes and control characters has been solved is a solid way with OUTPUTFORMATTER::Quoted() and DSNLEXER::NextTok().

Revision history for this message
Martin Errenst (imp-d) wrote :

r2851 stable flagged this as fixed.

Changed in kicad:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.