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

Unreachable code / semantic error in oauth2_client

    XMLWordPrintable

    Details

      Description

      There is an if condition in oauth2_client that is likely an error: https://github.com/moodle/moodle/blob/bf919ddf021cacb6711bd00fa3b3b97019ad450a/lib/oauthlib.php#L507
       

      if (!$this->info['http_code'] === 200) {
          throw new moodle_exception('Could not upgrade oauth token');
      

      I assume that something along the lines of "HTTP code is not equal to 200" was intended. However, PHP interprets this statement as

      if ((!$this->info['http_code']) === 200) {
      

      ...i.e. "!" negates $this->info['http_code'] instead of the entire expression. Since $this->info['http_code'] is usually (always?) truthy, !$this->info['http_code'] is false which is definitely never identical to 200. Therefore, the exception-throwing part is never reached.

      This would solve it:

      if (!$this->info['http_code'] !== 200) {
      

      I am going to prepare a patch.

        Attachments

          Activity

            People

            Assignee:
            jan.dagefoerde Jan Dageförde
            Reporter:
            jan.dagefoerde Jan Dageförde
            Peer reviewer:
            Ankit Agarwal
            Integrator:
            David Monllaó
            Tester:
            CiBoT
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              8/May/17