therealkdawg
therealkdawg

Reputation: 25

Linebreaks in a JIRA HTTP call

My automation setup makes a HTTP call to JIRA that includes a variable pulled from the test results before that. The variable sometimes has line breaks which error out the HTTP call because of syntax issues.

{
"fields": {
   "project":
   {
      "key": "Blah"
   },
   "assignee": {
      "name": "Joe"
    },
   "summary": "Summary",
   "description": "${variable}",
   "issuetype": {
      "name": "Defect"
   }
}

In the HTTP call, ${variable} is replaced with this:

{
"fields": {
   "project":
   {
      "key": "Blah"
   },
   "assignee": {
      "name": "Joe"
    },
   "summary": "Summary",
   "description": "Test failed: text expected to equal /

****** received  : 
[[[{"id":700,"status":"FAIL","color":"#D45D52","testKey":"TEST-329","testExecKey":"TEST-355","assig...]]]

****** comparison: [[[asdasdasdasd                                                                                           
]]]

/",

   "issuetype": {
      "name": "Defect"
   }
}

As a response I get this:

{"errorMessages":["Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@39cf8e10; line: 14, column: 62]"]}

How can I implement the variable so that the format does not break?

Upvotes: 0

Views: 1882

Answers (1)

Slotheroo
Slotheroo

Reputation: 975

This post suggests that you should replace the newline characters with escaped newline characters (i.e. before sending your variable, iterate through it and replace all \n with \\n)

Upvotes: 1

Related Questions