Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-54868

Change of encoding behaviour in XMLRPC web services

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Create a course with non-ascii, UTF-8 encoded characters in the name (you can get some fun ones here)
      2. Go to "Site administration" > "Advanced features"
      3. Check "Enable web services"
      4. Go to "Site administration" > "Plugins" > "Web services" > "Manage protocols"
      5. Enable XML-RPC
      6. Go to Site administration ► Plugins ► Web services ► External services
      7. Edit moodle mobile web service and enable it.
      8. Go to "Site administration" > "Plugins" > "Web services" > "Manage tokens"
      9. Add a token for the admin user. Set the service to the Moodle mobile webservice
      10. Using a terminal:

        curl 'http://[SERVER_ADDRESS_HERE]/stable_master/webservice/xmlrpc/server.php?&wstoken=[TOKEN_HERE]' -H "Content-Type: text/xml" --data "<?xml version='1.0' encoding='UTF-8'?><methodCall><methodName>core_course_get_courses</methodName><params> </params></methodCall>"

      11. Verify you see the course name as you entered it in step 1
        • NB: For this to work your terminal must be set to use the UTF-8 encoding. If it isn't you will most likely see the "special" characters from the course title replaced with two or three seemingly random characters
      Show
      Create a course with non-ascii, UTF-8 encoded characters in the name (you can get some fun ones here ) Go to "Site administration" > "Advanced features" Check "Enable web services" Go to "Site administration" > "Plugins" > "Web services" > "Manage protocols" Enable XML-RPC Go to Site administration ► Plugins ► Web services ► External services Edit moodle mobile web service and enable it. Go to "Site administration" > "Plugins" > "Web services" > "Manage tokens" Add a token for the admin user. Set the service to the Moodle mobile webservice Using a terminal: curl 'http://[SERVER_ADDRESS_HERE]/stable_master/webservice/xmlrpc/server.php?&wstoken=[TOKEN_HERE]' -H "Content-Type: text/xml" --data "<?xml version='1.0' encoding='UTF-8'?><methodCall><methodName>core_course_get_courses</methodName><params> </params></methodCall>" Verify you see the course name as you entered it in step 1 NB: For this to work your terminal must be set to use the UTF-8 encoding. If it isn't you will most likely see the "special" characters from the course title replaced with two or three seemingly random characters
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull Master Branch:
      MDL-54868-master
    • Sprint:
      3.2 Sprint 2

      Description

      After upgrading to Moodle 3.1, I noticed a problem with encoding for special chars when fetching data via web services in XMLRPC.

      I test the same client script to fetch the same data from a Moodle 3.0 and a Moodle 3.1 installations:

      • In Moodle 3.0, reply is as expected, and I get: a test course ÑÑÑ
      • In Moodle 3.1, encoding is different, and I get: a test course ÑÑÑ

      This happens the same when I use my own web services, and when I use the core Moodle ones.
      I could not find any info about any required changes on web services after upgrading to Moodle 3.1, so I wanted to know if this is an error in Moodle, or if there is something I need to change in client code.

      Tes script used is:


      $token = 'a3a57916df3910e094e23e572e2a817b';
      $domainname = 'http://localhost/j30/moodle';
      $functionname = 'core_course_get_courses';

      $params = array ();

      /// XML-RPC CALL
      header('Content-Type: text/plain');
      $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token;
      require_once('./curl.php');
      $curl = new curl;
      $curl->setHeader('Content-type: text/xml');
      $post = xmlrpc_encode_request($functionname, array($params));
      $resp = xmlrpc_decode($curl->post($serverurl, $post));
      echo ($resp[1]['fullname']);


      Thanks,
      Antonio

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Jul/16