z4r / python-rtkit

Python Api for Request Tracker's REST interface
http://z4r.github.com/python-rtkit/
Other
68 stars 44 forks source link

urlencoded text in comment body #36

Closed garw closed 11 years ago

garw commented 11 years ago

Hi,

since the update to 0.6.1 I have the problem that the text in the body of responses and comments is still urlencoded in RT. It seems that it does not get urldecoded by RT. I'm testing with RT Version 4.0.7. What do I do wrong?

z4r commented 11 years ago

Could you make some test here http://rt.easter-eggs.org/demos/ With different versions? And plz write in this issue URLs of you test. Thx

garw commented 11 years ago

Hi,

I narrowed the problem down to the following:

If I attach a file to my comment posting, the content type of the post changes from application/x-www-form-urlencoded to multipart/form-data. The section with the request variable has content type text/plain but is in fact urlencoded. I tried the following test script:

from rtkit.resource import RTResource
from rtkit.authenticators import CookieAuthenticator
from rtkit.errors import RTResourceError

from rtkit import set_logging
import logging
import sys 
set_logging('debug')
logger = logging.getLogger('rtkit')

TEST_VERSION="4.0"

RTUSER="john.foo"
RTPW="john.foo"
RTURL="http://rt.easter-eggs.org/demos/{}/REST/1.0/".format(TEST_VERSION)

rt = RTResource(RTURL, RTUSER, RTPW, CookieAuthenticator)

data = { 
    "content" : { 
        "Queue" : "Sales",
        "Subject" : "URLEncoding Test",
        "Requestor" : "url@encoding.org",
    }   
}
res = rt.post(path="ticket/new",payload=data)

tid = None
for k,v in res.parsed[0]:
    if k == "id":
        tid = v 
        break

if tid is None:
    print("Ticket creation failed")
    sys.exit(1)

resp_data = { 
    "content" : { 
        "Action" : "correspond",
        "Text" : "This is a simple test\nwith multiline\ncomment",
        "Attachment" : "informatik.png"
    },  
    "attachment_1" : file("informatik.png")
}

res = rt.post(path=(tid + "/comment"),payload=resp_data)

This produces a ticket which has the problem in the test-rt. However, as soon as you remove the attachment, everything works fine again.

So, I guess that the urlencode of the text should only happen if the data is not sent as multipart/form-data.