UTF8 circuit broken through an XML-RPC call

UTF8 circuit broken through an XML-RPC call

by Valery Fremaux -
Number of replies: 3

I noticed that an UTF-8 char sequenced string needed an utf8_encode() filtering before sending for getting retrieved correctly in remote Moodle. Did I miss someting in the path that would avoid such explcit adjustment ?

(giving as a 'string' argument to an XML-RPC call).

Average of ratings: -
In reply to Valery Fremaux

Re: UTF8 circuit broken through an XML-RPC call

by Nigel McNie -
I can't recall seeing anything especially UTF8 related in the MNET code - can you give more information about what you needed to do?
In reply to Nigel McNie

Re: UTF8 circuit broken through an XML-RPC call

by Valery Fremaux -
Nigel, basically, here is a typical case :

here is more or less the sequence I have :

// PREPARING

$userhost = get_field('mnet_host', 'wwwroot', 'id', $USER->mnethostid);
$rpcclient = new mnet_xmlrpc_client();
$rpcclient->set_method('blocks/file_manager/rpclib.php/file_manager_rpc_addlink');
$rpcclient->add_param($USER->username, 'string');
$rpcclient->add_param($userhost, 'string');
$rpcclient->add_param($CFG->wwwroot, 'string');
// fixes an XML-RPC transcoding issue...
$rpcclient->add_param(html_entity_decode(utf8_decode($linkname)), 'string');
$rpcclient->add_param($what, 'string');

$mnet_host = new mnet_peer();
$mnet_host->set_wwwroot($userhost);

// EXECUTING

if (!$rpcclient->send($mnet_host)){
if (debugging()){
print_object($rpcclient);
}
error(get_string('failed', 'file_manager').'<br/>'.implode("<br/>\n", $rpcclient->error));
}
print_object(json_decode($rpcclient->response));

(yes, I use jsoning the transmitted message as I noticed objet/array consistency issues when sendign complex structure directly. json_encoding makes structure being safe across tranport.)

the issue is marked as red : without the utf8_decode, the $linkname content, when using accent letters such in "Découvrir Pairform@nce" is retrieved with \uXXX encoded sequences at the other end, as an ISO escaped expression of UTF sequences. This is quite odd indeed, but I noticed that already when retrieving a remote course list through MNET remote enrollement : course names using UTF8 escapes come also backencoded.

Hope it helps you...
In reply to Valery Fremaux

Re: UTF8 circuit broken through an XML-RPC call

by Nigel McNie -
Interesting to know - maybe there is an issue in the xmlrpc_client class or in php's xmlrpc support? You'd have to trace the data all the way through to find out where things go wrong I guess.

This should probably be filed as a bug on the Moodle Tracker.