Escape invalid XML in rich text object

We’re using the API to pass the results of a Google Form into asana tasks for follow up, and I just encountered an issue where a co-worker pasted the error message from another application into the form field that ends up being passed to asana as html_description. This text contained a tag (<anonymous>) that asana rejected with the message:

{"errors":[{"error":"reasoned_xml_parsing_error","message":"XML is invalid,Unexpected tag ANONYMOUS","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}

According to the asana API docs, I “must provide similarly structured, valid XML.”; however, I can’t guarantee it in all circumstances. Is there a way for me to escape, process, or otherwise handle the data I pass to this field to solve this issue?

Thanks!

Hi @Clay_Roper,

The rich test in Asana’s API will only support HTML tags that are meaningful to rich text in the Asana web app. This way, every tag has a known and specific meaning that can translate exactly to what users see in tasks and comments. Accepting additional tags would mean that there is uncertainty in what the rich text means. You will have to ensure that the text you’re submitting contains only the tags listed in the table in our documentation. In this case, because the user copy-pasted the text from another system, I suspect what you actually want is to escape the user input with something like xml.sax.saxutils.escape in Python or org.apache.commons.lang.StringEscapeUtils.escapeXml in Java.

Hey Joe,

That’s what I figured. Thanks for confirming!

Best,

1 Like