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

Web service 2.0 why error messages in REST mode are passed to htmlentities before sending to client ?

    XMLWordPrintable

Details

    • Any
    • MOODLE_21_STABLE
    • Hide

      see above

      Show
      see above

    Description

      Hello,

      While testing 2.0 Web Service, and more specifically integration of oktech operations under 2.0 infrastructure I noticed that error messages in REST protocol were returned to client after conversion to html entities. This has two unpleaseant side effects :

      1) when testing Web service under Site Administration, Development, Web service Test Client , output in case or error is messed by some HTML tags such as eacute; ocirc; ... see attached screenshot 1

      2) more annoying, when testing Web service with a browser such as Chrome by calling something like http://localhost/moodle.git/webservice/rest/server.php?wsfunction=oktech_get_users&wstoken=wrongtoken the returned error message cannot be parsed by Chrome due to unexpected entities. One has to selected 'see page source code' to discover the real error message . See attached screenshots

      I did fix it in by removing calls to htmlentities in function send_error in webservice/rest/locallib.php

      protected function send_error($ex=null) {
      $this->send_headers();
      $xml = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
      $xml .= '<EXCEPTION class="'.get_class($ex).'">'."\n";
      $xml .= '<MESSAGE>'.htmlentities($ex->getMessage(), ENT_COMPAT, 'UTF-8').'</MESSAGE>'."\n";
      if (debugging() and isset($ex->debuginfo))

      { $xml .= '<DEBUGINFO>'.htmlentities($ex->debuginfo, ENT_COMPAT, 'UTF-8').'</DEBUGINFO>'."\n"; }

      $xml .= '</EXCEPTION>'."\n";
      echo $xml;
      }

      Cheers

      Attachments

        1. screenshot_002.png
          screenshot_002.png
          31 kB
        2. screenshot_003.png
          screenshot_003.png
          35 kB
        3. screenshot_004.png
          screenshot_004.png
          25 kB

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ppollet Patrick Pollet
              Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: