XML RPC API with special characters

LATEST Official version.
Questions and discussions - NO ISSUES
FOR ISSUES => http://mantis.testlink.org

Moderators: Amaradana, TurboPT, TL Developers

Post Reply
lindt888
TestLink user
Posts: 1
Joined: Fri Apr 27, 2012 7:39 pm

XML RPC API with special characters

Post by lindt888 »

I think I found a bug in one of the library that is used from TestLink 1.9, namely the "The Incutio XML-RPC Library for PHP" library. I already contacted incutio, but I would like to share these experiences with the Forum and maybe TestLink can implement the bug fix to make sure that the bug is really fixed in future version.

The problem arises when somebody enters binary data into a field of a test, and this field is then accessed using the XML-RPC API (this can happen because when a test fails and outputs some random data and the test just copies and pastes the random data, it could be that the random data contains binary stuff as well). When a client invokes the XML-RCP API to retrieve the test, Testlink will create an XML and send this XML back to the caller, but the XML contains invalid XML characters and therefore parsing the returned XML from Testlink gives back an error, e.g. the Xerces parser gives back this error message:

Code: Select all

----------------------
[Fatal Error] :1223:38: An invalid XML character (Unicode: 0x7) was found in the element content of
the document.
----------------------
@See here for more about which characters are allowed in XML: http://en.wikipedia.org/wiki/Valid_characters_in_XML

The solution would be that Testlink (using the The Incutio XML-RPC Library for PHP) would not sent back invalid XML, but would do something with invalid XML characters. One solution would be just to replace such characters with '?', or remove them entirely, or use base64 encoding for the whole field that contains invalid characters. As for me, I just did a hack which I don't like but which works:

Code: Select all

./third_party/xml-rpc/class-IXR.php:
function getXml() {
...
                if ($this->containsInvalidChars($this->data)) {
                  return '<string>XML contains invalid chars, base64 encoded: '.base64_encode($this->data).'</string>';
                } else {
                  return '<string>'.htmlspecialchars($this->data).'</string>';
                }
...
}

    function containsInvalidChars($str) {
      for ($i=0, $len=strlen($str);$i<$len;$i++) {
        $letter = ord(substr($str, $i, 1));
        if ($letter < 32) {
          return true;
          if ($str[$i] == 9) { continue;}
          if ($str[$i] == 10) { continue;}
          if ($str[$i] == 13) { continue;}
          return true;
        }
      }
      return false;
    }
Any help, ideas?
Thanks a lot.
Michael
Post Reply