API post creation breaks if post contains an ampersand

(Niv Shah) #1

When posting to the /post end point to create a post (a little redundant I know), if the raw parameter contains an ‘&’, the body of the created post will contain everything up to that ‘&’ but won’t include the ‘&’ or anything after it. For example:

curl -X POST -d topic_id=topic_id -d raw="This is a test post with an ampersand & nothing after the ampersand will show up in the post" http://discourse.example.com/posts?api_key=api_key&api_username=api_username

The post is still created, so I imagine there is something bugged out on the /post endpoint? I tried changing ‘&’ to something html-safe like ‘&’ but the post body ends no matter what at the ‘&’.

EDIT: To add some more context, if I pass along a raw parameter such as: -d raw="This is a test post with an ampersand \\& does it work"

The response contains:
"cooked":"\u003cp\u003eThis is a test post with an ampersand \\\u003c/p\u003e"

(Mittineague) #2

Have you tried escaping with backslashes?

I’m taking a wild guess you’ll need two

blah blah \\& blah

(Niv Shah) #3

Gave it a shot, but no such luck. Still getting a hard cut-off at the ‘&’.

(Eli the Bearded) #4

Have you tried a URL % encoding? Ampersand is %26, I’m pretty sure.

(Niv Shah) #5

This seems to have solved it! Thank you for the pointer