Newlines in comments?

18 views
Skip to first unread message

Tim Ward

unread,
Aug 29, 2017, 11:19:34 AM8/29/17
to Trac Users
Entering a newline in a comment as "\n" via the XMLRPC plugin doesn't work - the comment fails to appear in the ticket (and so far as I can see there are no error messages in any logs anywhere).

So I tried the various other ways of entering newlines, such as "[[BR]]", with weird results. A two line comment with the lines separated by "[[BR]]" sometimes appears as two lines in the Trac browser UI, and sometimes appears as a single line with the text "[[BR]]" in the middle. (I didn't get anything noticeably different, so far as I recall, with "[[br]]" or "\\".)

I haven't been able to determine what decides the "sometimes", although it may have something to do with what string immediately precedes the "[[BR]]". Eventually I found that putting a space first, so " [[BR]]" worked insofar as that consistently gives two separate lines in the comment as displayed in the Trac browser UI ...

... but I now discover it sometimes (at least) gives a single line with " [[BR]]" in the middle in the notification email.

How, please, can I consistently and correctly

(1) add a multi-line comment to a ticket via the XMLRPC plugin
(2) so that it displays as multiple lines in the Trac browser UI
(3) and also displays as multiple lines in the notification email

?

Ryan Ollos

unread,
Aug 30, 2017, 2:08:01 AM8/30/17
to Trac Users
A code snippet showing the method calls you are using may help with identifying the issue.

- Ryan
 

Tim Ward

unread,
Aug 30, 2017, 4:09:53 AM8/30/17
to Trac Users, rjo...@gmail.com
    data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ], "method": "ticket.update" }}'

    r = requests.post( url, data=data.format( ticketId, comment ), headers=headers, auth=auth )

(Python) - how do I usefully include a line break in the content of the comment string variable?

RjOllos

unread,
Aug 30, 2017, 2:09:40 PM8/30/17
to Trac Users, rjo...@gmail.com


On Wednesday, August 30, 2017 at 1:09:53 AM UTC-7, Tim Ward wrote:
    data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ], "method": "ticket.update" }}'

    r = requests.post( url, data=data.format( ticketId, comment ), headers=headers, auth=auth )

(Python) - how do I usefully include a line break in the content of the comment string variable?

Your code snippet uses Requests, but your earlier comment discussed using XmlRpcPlugin. If you want to send rpc requests you should use xmlrpclib:

... or did I misread your intention?

- Ryan

Tim Ward

unread,
Aug 30, 2017, 3:39:06 PM8/30/17
to trac-...@googlegroups.com
Whether I use that library or not the data is going to be sent over the same HTTP interface so why would it matter which layers of libraries I use at the client side?
--
You received this message because you are subscribed to a topic in the Google Groups "Trac Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/trac-users/g8PAErIOgLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to trac-users+...@googlegroups.com.
To post to this group, send email to trac-...@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/d/optout.

-- 
Tim Ward
Brett Ward Ltd - www.brettward.co.uk - 07801 703 600

Jun Omae

unread,
Sep 1, 2017, 12:16:04 PM9/1/17
to trac-...@googlegroups.com
On Wed, Aug 30, 2017 at 5:09 PM, Tim Ward <t...@brettward.co.uk> wrote:
> data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ],
> "method": "ticket.update" }}'
>
> r = requests.post( url, data=data.format( ticketId, comment ),
> headers=headers, auth=auth )
>
> (Python) - how do I usefully include a line break in the content of the
> comment string variable?

Your generated json string is incorrect. Your request with the
incorrect json leads error response from XMLRPC plugin.

>>> data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ], "method": "ticket.update" }}'
>> print(data.format(42, 'line 1\nline 2\n'))
{ "params": [ 42, "line 1
line 2
", { "action": "leave" }, true ], "method": "ticket.update" }

You should use json.dumps() rather than directly generating json
string if you cannot implement it.

>>> import json
>>> ticketId = 42
>>> comment = 'line 1\nline 2\n'
>>> data = {'params': [ticketId, comment, {'action': 'leave'}, True], 'method': 'ticket.update'}
>>> print(json.dumps(data))
{"params": [42, "line 1\nline 2\n", {"action": "leave"}, true],
"method": "ticket.update"}

--
Jun Omae <jun...@gmail.com> (大前 潤)

Tim Ward

unread,
Sep 1, 2017, 12:33:25 PM9/1/17
to trac-...@googlegroups.com
Ah. Thanks. I'll give that a try next week.

It won't of course explain why "[[BR]]" is unreliable even when entered
from the browser, so it sounds like I could have come across more than
just one problem.

Tim Ward

unread,
Sep 4, 2017, 5:09:27 AM9/4/17
to trac-...@googlegroups.com
Thanks. That sorts out the use of "\n". It doesn't of course sort out why "[[BR]]" only works a bit sometimes, but as I've got "\n" working I don't care about "[[BR]]" any more.
Reply all
Reply to author
Forward
0 new messages