[wp-trac] [WordPress Trac] #52892: Privacy Export Personal Data: JSON encoding failure generates invalid JSON in export file

WordPress Trac noreply at wordpress.org
Tue Mar 23 19:37:29 UTC 2021


#52892: Privacy Export Personal Data: JSON encoding failure generates invalid JSON
in export file
----------------------------+-----------------------------
 Reporter:  hellofromTonya  |       Owner:  hellofromTonya
     Type:  defect (bug)    |      Status:  assigned
 Priority:  normal          |   Milestone:  5.8
Component:  Privacy         |     Version:  5.4
 Severity:  normal          |  Resolution:
 Keywords:  dev-feedback    |     Focuses:
----------------------------+-----------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch => dev-feedback
 * owner:  (none) => hellofromTonya
 * status:  new => assigned
 * milestone:  Awaiting Review => 5.8


Comment:

 Moving into 5.8 milestone for visibility. Removed `has-patch` as the PR is
 currently a draft.

 Proposing 2 different solutions:

 Fix #1:
 Send a JSON error
 {{{#!php
 // Convert the groups to JSON format.
 $groups_json = wp_json_encode( $groups );
 if ( false === $groups_json ) {
         wp_send_json_error( __( 'Unable to encode the export file (JSON
 report).' ) );
 }
 }}}

 This fix is breaking change as the files will not be generated or
 downloaded.

 Fix #2:

 Fix the type mismatch and then either trigger a notice or warning (to
 alert of the problem) or `_doing_it_wrong`.

 {{{#!php
 // Convert the groups to JSON format.
 $groups_json = wp_json_encode( $groups );
 if ( false === $groups_json ) {
         $groups_json = '"false"';
         trigger_error( __( 'Unable to encode the export file (JSON
 report).' ), E_USER_NOTICE );
 }

 }}}

 or
 {{{#!php
 // Convert the groups to JSON format.
 $groups_json = wp_json_encode( $groups );
 if ( false === $groups_json ) {
         $groups_json = '"false"';
         _doing_it_wrong(
                 __FUNCTION__,
                 __( 'Unable to encode the export file (JSON report).' ),
                 '5.8.0'
         );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52892#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list