Skip to:
Content

BuddyPress.org

Changeset 11097


Ignore:
Timestamp:
09/13/2016 09:14:06 PM (9 years ago)
Author:
r-a-y
Message:

Core: Fix fatal error with bp_core_get_iso8601_date() when an invalid date string is passed.

This error occurred on the Members Directory and selecting the
"Alphabetical" filter when attempting to parse an inactive user's last
activity. Inactive users passes the "Never active" string to
bp_core_get_iso8601_date() and the DateTime class causes a fatal
error on invalid date strings, unless we catch the exception, which this
commit is now doing.

See #5757.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r11088 r11097  
    13091309        }
    13101310
    1311         $date = new DateTime( $timestamp, new DateTimeZone( 'UTC' ) );
     1311        try {
     1312            $date = new DateTime( $timestamp, new DateTimeZone( 'UTC' ) );
     1313
     1314        // Not a valid date, so return blank string.
     1315        } catch( Exception $e ) {
     1316            return '';
     1317        }
     1318
    13121319        return $date->format( DateTime::ISO8601 );
    13131320    }
  • trunk/tests/phpunit/testcases/core/functions.php

    r11082 r11097  
    254254
    255255        $this->assertEquals( 'March 18, 2014 at 7:00 pm', bp_format_time( $time, $just_date, $localize_time ) );
     256    }
     257
     258    /**
     259     * @group bp_core_get_iso8601_date
     260     */
     261    public function test_bp_core_get_iso8601_date_invalid_date() {
     262        $this->assertEquals( '', bp_core_get_iso8601_date( 'Not a date' ) );
    256263    }
    257264
Note: See TracChangeset for help on using the changeset viewer.