Skip to content

Commit a178258

Browse files
committed
Collaboration: Gate db_error on WP_DEBUG and fix JSON decode inconsistency
- Only include $wpdb->last_error in REST error responses when WP_DEBUG is true, matching core REST API conventions and preventing table/column name leakage on production sites - Normalize JSON decode validation in get_updates_after_cursor() to use is_array() instead of json_last_error(), consistent with get_awareness_state() in the same class
1 parent 3a0d1e4 commit a178258

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/wp-includes/collaboration/class-wp-collaboration-table-storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
202202
$updates = array();
203203
foreach ( $rows as $row ) {
204204
$decoded = json_decode( $row->update_value, true );
205-
if ( json_last_error() === JSON_ERROR_NONE ) {
205+
if ( is_array( $decoded ) ) {
206206
$updates[] = $decoded;
207207
}
208208
}

src/wp-includes/collaboration/class-wp-http-polling-collaboration-server.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,14 @@ private function process_collaboration_update( string $room, int $client_id, int
453453
if ( ! $has_newer_compaction ) {
454454
if ( ! $this->storage->remove_updates_before_cursor( $room, $cursor ) ) {
455455
global $wpdb;
456+
$data = array( 'status' => 500 );
457+
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
458+
$data['db_error'] = $wpdb->last_error;
459+
}
456460
return new WP_Error(
457461
'rest_collaboration_storage_error',
458462
__( 'Failed to remove updates during compaction.' ),
459-
array(
460-
'status' => 500,
461-
'db_error' => $wpdb->last_error,
462-
)
463+
$data
463464
);
464465
}
465466

@@ -512,13 +513,14 @@ private function add_update( string $room, int $client_id, string $type, string
512513

513514
if ( ! $this->storage->add_update( $room, $update ) ) {
514515
global $wpdb;
516+
$data = array( 'status' => 500 );
517+
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
518+
$data['db_error'] = $wpdb->last_error;
519+
}
515520
return new WP_Error(
516521
'rest_collaboration_storage_error',
517522
__( 'Failed to store collaboration update.' ),
518-
array(
519-
'status' => 500,
520-
'db_error' => $wpdb->last_error,
521-
)
523+
$data
522524
);
523525
}
524526

0 commit comments

Comments
 (0)