Opened 7 months ago

# An invalid XML character (Unicode: 0x1b) was found in the element content of the document.

Reported by: Owned by: sanket.modi@… osimons high XmlRpcPlugin major 1.0

### Description

There is a ticket which contains some Escape characters and when we try to get that ticket using API, it gives us error "An invalid XML character (Unicode: 0x1b) was found in the element content of the document".

As there are some invalid XML characters which parser can't parse, we suggest you to remove those before sending XML.

### comment:1 Changed 7 months ago by osimons

1) According to XML spec the 0x1b character is indeed not valid in XML and should not be included.

2) However since Trac web output is also X(HT)ML, it would actually be illegal to return it in that response too. Does a regular web response of the ticket include the illegal characters or are they then stripped away?

3) If stripped away - from either web or rpc - how would you handle field updates? That would obviously overwrite the control characters as they would not be included when post'ing back new data?

4) If such control characters are troublesome, would it not be an equally good strategy to ensure that they don't make it into the database in the first place?

Anyway, it could likely be done quite simply in tracrpc/xml_rpc.py by editing _send_reponse() to this (using multiple lines for clarity):

_illegal_xml_chars_RE = re.compile(
u'[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]')
...
def _send_response(self, req, response, content_type='application/xml'):
response = to_unicode(response)
response = _illegal_xml_chars_RE.sub('?', response)
response = response.encode("utf-8")
...


### Modify Ticket

Change Properties