[wp-trac] [WordPress Trac] #46329: sanitize_text_field after 5.1 update should account for __toString() methods

WordPress Trac noreply at wordpress.org
Sat Feb 23 15:34:50 UTC 2019


#46329: sanitize_text_field after 5.1 update should account for __toString()
methods
-------------------------+-----------------------------
 Reporter:  fclaussen    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Formatting   |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Since 5.1 the `sanitize_text_field` changed to check if the parameter is
 an object or array.
 That broken one of my codes and possibly for other people too because I
 was passing a `SimpleXMLElement Object`. It has a magic `__toString()`
 method that gets called when you do that type conversion.

 As @iCaleb suggested in #41450, we may want to add another check.


 {{{#!php
 <?php
 if ( ( is_object( $str ) && ! method_exists( $str, '__toString' ) ) ||
 is_array( $str ) ) {
   return '';
 }
 }}}

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


More information about the wp-trac mailing list