php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55448 Error at a Soap request
Submitted: 2011-08-18 14:10 UTC Modified: 2011-08-18 14:22 UTC
Votes:5
Avg. Score:3.6 ± 1.2
Reproduced:3 of 5 (60.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: sunfundev at gmail dot com Assigned:
Status: Open Package: SOAP related
PHP Version: 5.3.6 OS: Windows/FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-08-18 14:10 UTC] sunfundev at gmail dot com
Description:
------------
PHP 5.3.6 on Windows and FreeBSD

There is a problem with soap-call when one of the parameters contains control
characters.

Expected result:
----------------
$options = array(
	"location" => Config::$config['soap_location'],
	"uri" => Config::$config['soap_uri'],
	"trace" => 1,
	"exceptions" => true
);

$soap_client = new SoapClient(null, $options);
$result = $soap_client->login(array('user_name'=>Config::$config['login'],'password'=Config::$config['password']));
$session_id = $result->id;

$entrie = array(
	array('name' => 'first_name', 'value' => 'normal string'),
	array('name' => 'last_name', 'value' => (string)chr(0x1A)),
	array('name' => 'email1', 'value' => 'soaptest@soaptest.com')
	);

$soap_client->__soapCall("set_entries", array($session_id, 'Leads', array($entrie)));

Actual result:
--------------
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] error in msg parsing:
XML error parsing SOAP payload on line 2: Invalid character in H:\xampp\htdocs\test.php:55
Stack trace:
#0 H:\xampp\htdocs\test.php(55): SoapClient->__soapCall('set_entries', Array)
#1 {main}
  thrown in H:\xampp\htdocs\test.php on line 55

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-18 14:22 UTC] sunfundev at gmail dot com
-Summary: XML Error when +Summary: Error at a Soap request
 [2011-08-18 14:22 UTC] sunfundev at gmail dot com
Change title
 [2011-11-22 18:23 UTC] benbunk at gmail dot com
PHP 5.2.10 on RHEL 5 (Versions irrelevant) 

Description: 
Ideally, a xml_encode or xmlspecialchars function would be created to handle this. 

There is a set list of acceptable chars in the xml documentation. All other characters not in this list should be excluded. Here is a short list (more found at the documentation link provided): 

Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]	/* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */

Documentation:
--------------
W3C. Extensible Markup Language (XML) 1.0 (Fifth Edition). W3C XML Working Group. 2008. (http://www.w3.org/TR/xml/#charsets)

Work around:
------------
Here's a simple function in php that can strip out the control characters which is a good-enough solution but far from complete: 

function xmlspecialchars($escapStr) {
  $needles = array(
    chr(0x0),
    chr(0x01),
    chr(0x02),
    chr(0x03),
    chr(0x04),
    chr(0x05),
    chr(0x06),
    chr(0x07),
    chr(0x08),
    chr(0x09),
    chr(0x1),
    chr(0x10),
    chr(0x11),
    chr(0x12),
    chr(0x13),
    chr(0x14),
    chr(0x15),
    chr(0x16),
    chr(0x17),
    chr(0x18),
    chr(0x19),
    chr(0x2),
    chr(0x3),
    chr(0x9),
    chr(0xa),
    chr(0xb),
    chr(0xc),
    chr(0xd),
    chr(0xe),
    chr(0xf),
  );

  return str_replace($needles, ' ', $escapStr);
}
 [2011-11-30 20:53 UTC] benbunk at gmail dot com
My suggested work-around does not work.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Sep 15 12:01:26 2019 UTC