[wp-trac] [WordPress Trac] #51389: REST API: WP_REST_Meta_Fields::default_additional_properties_to_false assumes that the schema has properties.

WordPress Trac noreply at wordpress.org
Thu Sep 24 08:32:52 UTC 2020


#51389: REST API: WP_REST_Meta_Fields::default_additional_properties_to_false
assumes that the schema has properties.
--------------------------+-----------------------------
 Reporter:  austin880625  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 This function simply traverses through {{{$schema}}} object and doesn't
 intend to do any type check on schema. Hence it may need to check
 existence of properties before traverse into it.

 It affect the REST API response for post that has meta with {{{object}}}
 type, the warning message {{{PHP Warning: Invalid argument supplied for
 foreach()   in ...}}} will corrupt the json output if the
 {{{error_reporting}}} configuration is low enough.

 The problem can be reproduced with the following meta registration in a
 plugin:
 {{{#!php
 <?php
 function test_register_post_meta() {
     register_post_meta('post', 'test_key', array(
         'type' => 'object',
         'show_in_rest' => true,
     ));
 }
 add_action('init', 'test_register_post_meta');
 ?>
 }}}

 #48785 might be related. They add test for that case, but I'm not sure
 what behavior should I test over in my case(for eliminating an warning
 without affecting the final result).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51389>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list