php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47273 Encoding bug in SoapServer->fault
Submitted: 2009-02-02 10:16 UTC Modified: 2009-08-26 14:06 UTC
From: shaselboeck at m-s dot de Assigned: dmitry (profile)
Status: Closed Package: SOAP related
PHP Version: 5.2.8 OS: Windows
Private report: No CVE-ID: None
 [2009-02-02 10:16 UTC] shaselboeck at m-s dot de
Description:
------------
Setting up an SoapServer with another encoding as UTF-8 - for example Cp1252 - SoapServer->fault() will not correct encode the message.

By throwing a SoapFault with an message, the encoding will be done correctly, but SoapServer->fault() does not.

To suppress error, I run an internal encoding.
mb_convert_encoding($string, 'UTF-8', $this->getEncoding());

Reproduce code:
---------------
All code listed here is part of a complex class hierarchy in combination with the Zend Framework.

--------------------------------------------
SERVER-CODE
----------------------- ---------------------
$server = new SoapServer('http://xxx.de/?wsdl', array('encoding' => 'Cp1252'));
$server->setClass('SoapFaultTest');

try {
    $server->handle();
}
catch (Exception $e) {
    $this->fault('Sender', $e->getMessage());
}

--------------------------------------------
CLIENT-CODE
--------------------------------------------
try {
    $client = new SoapClient('http://xxx.de/?wsdl', array('encoding' => 'Cp1252'));
    echo $client->test();
}
catch (SoapFault $fault) {
    echo 'Error: ' . $fault->getMessage();
}

--------------------------------------------
SERVICE-CLASS SoapFaultTest
--------------------------------------------
class SoapFaultTest
{
    public function test() {
        throw new Exception('Exception with some special chars: ???');
    }
}

Expected result:
----------------
Exception with some special chars: ???

Actual result:
--------------
SOAP-ERROR: Encoding: string 'Exception with some special chars: \xc4...' is not a valid utf-8 string

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-18 14:23 UTC] dmitry@php.net
I cannot reproduce it.

Do you have the bag only with faults?
Doesn't it occur if you just return string with special characters?

May be the bug is related to ext/mbstring. Try to set mbstring.http_input and mbstring.http_output to "pass".
 [2009-03-10 14:13 UTC] shaselboeck at m-s dot de
I set up a new test with XAMPP Lite 1.7.0 (Apache 2.2.11 + PHP 5.2.8).
The following 3 files are located in: http://localhost/soap/

Here my soap-server (index.php)
------------------------------------------------------------
<?php
require('SoapFaultTest.php');

$server = new SoapServer(null, array('uri' => 'http://localhost/soap/', 'encoding' => 'ISO-8859-1'));
$server->setClass('SoapFaultTest');

try {
	$server->handle();
} catch (Exception $e) {
	$server->fault("Sender", $e->getMessage());
}
?>


My service class (SoapFaultTest.php)
------------------------------------------------------------
<?php
class SoapFaultTest
{
    public function test() {
    	//  Test #1
        return 'Test #1 exception with some special chars: ???';
        
        //  Test #2
        //throw new Exception('Test #2 exception with some special chars: ???');
    }
}
?>


And my soap-client (client.php)
------------------------------------------------------------
<?php
try {
    $client = new SoapClient(null, array(
		'location'	=> 'http://127.0.0.1/soap/index.php',
		'uri'		=> 'http://127.0.0.1/soap/',		
		'encoding'	=> 'ISO-8859-1')
	);    
    echo $client->test();
}
catch (SoapFault $fault) {
    echo 'Error: ' . $fault->getMessage();
}
?>


Getting test-results by http://localhost/soap/client.php:

Test #1 - result as expected:
Test #1 exception with some special chars: ???

Test #2 - result:
Error: SOAP-ERROR: Encoding: string 'Test #2 exception with some special chars: \xc4...' is not a valid utf-8 string

Test #2 - expected:
Test #2 exception with some special chars: ???

SoapServer->fault() ignores the encoding!
Hope you can now reproduce the bug.
 [2009-08-26 14:05 UTC] svn@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&revision=287746
Log: Fixed bug #47273 (Encoding bug in SoapServer->fault)
 [2009-08-26 14:06 UTC] dmitry@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC