Bug 841229 - Collapsing of whitespace in <screen> and <programlisting> when PUT using REST?
Summary: Collapsing of whitespace in <screen> and <programlisting> when PUT using REST?
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: PressGang CCMS
Classification: Community
Component: REST-API
Version: 1.x
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: Matthew Casperson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-07-18 13:25 UTC by Stephen Gordon
Modified: 2014-08-04 22:27 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-07-23 00:16:33 UTC
Embargoed:


Attachments (Terms of Use)
Fixed Put Script (1.74 KB, application/x-shellscript)
2012-07-23 00:15 UTC, Lee Newson
no flags Details

Description Stephen Gordon 2012-07-18 13:25:58 UTC
Description of problem:

I recently wrote some simple bash scripts that allow me to get/put topics via the REST interface (allowing them to be edited in my local editor). This works pretty well so far, but I have noticed when saving topics using the REST API newlines inside <screen> and <programlisting> tags are lost.

When I go into skynet itself and put the newlines back in and save the topic the newlines are saved correctly. As a result I think either:

- I'm doing something wrong in the way I am formatting the PUT request, this would be my first assumption except that it only appears to impact newlines in these specific elements while I treat all text the same in my script.

or;

- the REST API is removing the newlines when processing/saving.

I'll post a follow up link as a private comment linking my script(s) but essentially the way I escape the XML string before sending it to the API is covered in my stackoverflow answer [1]. The replacement for newlines is:

JSON_TOPIC_RAW=${JSON_TOPIC_RAW//^@/\\\n} # \n (newline)

Where ^@ is VIM's representation of the newline control character.

[1] http://stackoverflow.com/questions/10053678/escaping-characters-in-bash-for-json/11495576#11495576

Comment 2 Lee Newson 2012-07-23 00:15:19 UTC
Created attachment 599658 [details]
Fixed Put Script

Comment 3 Lee Newson 2012-07-23 00:15:52 UTC
I had a look at this and the issue is in the skynet-put.sh script. You aren't currently escaping the '\n' character as it is in byte form and as such it is removed from the push. I'm not 100% sure on this but I believe the '@' is only displayed during runtime (to give a visual representation of where new lines are) and is never saved to the file. 

The only reason the other elements have the new lines is because of the formatting done by Skynet. However Skynet will preserve the contents of screen, programlisting and a couple other verbatim Docbook XML elements.

I've attached a corrected script that preserves the '\n' character (I also left the '@' replacement in to be sure).

Comment 4 Stephen Gordon 2012-07-23 15:18:28 UTC
THe ^@ isn't saved to file, the control character it represents is. Control characters are by definition non-displayable.


Note You need to log in before you can comment on or make changes to this bug.