Skip to content

Commit 4fea2cc

Browse files
committed
Account for non-string values sent to json_to_datetime
1 parent cd43069 commit 4fea2cc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

includes/CMB2_Utils.php

+4
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ public static function unserialize_datetime( $date_value ) {
583583
* @return DateTime|null
584584
*/
585585
public static function json_to_datetime( $json_string ) {
586+
if ( ! is_string( $json_string ) ) {
587+
return null;
588+
}
589+
586590
$json = json_decode( $json_string );
587591

588592
// Check if json decode was successful

tests/test-cmb-utils.php

+1
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public function test_json_to_datetime() {
370370

371371
$this->assertEquals( $datetime, CMB2_Utils::json_to_datetime( $json ) );
372372
$this->assertNull( CMB2_Utils::json_to_datetime( $evil_eval ) );
373+
$this->assertNull( CMB2_Utils::json_to_datetime( [ $json ] ) );
373374
}
374375

375376
}

0 commit comments

Comments
 (0)