Bug 841229 - Collapsing of whitespace in <screen> and <programlisting> when PUT using REST?
Collapsing of whitespace in <screen> and <programlisting> when PUT using REST?
Status: CLOSED NOTABUG
Product: PressGang CCMS
Classification: Community
Component: REST-API (Show other bugs)
1.x
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Matthew Casperson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-18 09:25 EDT by Stephen Gordon
Modified: 2014-08-04 18:27 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-07-22 20:16:33 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Stephen Gordon 2012-07-18 09:25:58 EDT
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-22 20:15:19 EDT
Created attachment 599658 [details]
Fixed Put Script
Comment 3 Lee Newson 2012-07-22 20:15:52 EDT
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 11:18:28 EDT
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.