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

            jan.dagefoerde Jan Dageförde
            jan.dagefoerde Jan Dageförde
            Ankit Agarwal Ankit Agarwal
            David Monllaó David Monllaó
            CiBoT CiBoT
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              8/May/17