Make WordPress Core

Changeset 20539


Ignore:
Timestamp:
04/19/2012 07:46:34 PM (14 years ago)
Author:
nacin
Message:

Add sanity checks to WP_oEmbed::data2html() to ensure we are working with scalar values. Always use the filter. props mdawaffe, fixes #20322.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-oembed.php

    r20235 r20539  
    228228         */
    229229        function data2html( $data, $url ) {
    230                 if ( !is_object($data) || empty($data->type) )
     230                if ( ! is_object( $data ) || empty( $data->type ) )
    231231                        return false;
     232
     233                $return = false;
    232234
    233235                switch ( $data->type ) {
    234236                        case 'photo':
    235                                 if ( empty($data->url) || empty($data->width) || empty($data->height) )
    236                                         return false;
    237 
    238                                 $title = ( !empty($data->title) ) ? $data->title : '';
     237                                if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) )
     238                                        break;
     239                                if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) )
     240                                        break;
     241
     242                                $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : '';
    239243                                $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" /></a>';
    240244                                break;
    … …  
    242246                        case 'video':
    243247                        case 'rich':
    244                                 $return = ( !empty($data->html) ) ? $data->html : false;
     248                                if ( ! empty( $data->html ) && is_string( $data->html ) )
     249                                        $return = $data->html;
    245250                                break;
    246251
    247252                        case 'link':
    248                                 $return = ( !empty($data->title) ) ? '<a href="' . esc_url($url) . '">' . esc_html($data->title) . '</a>' : false;
     253                                if ( ! empty( $data->title ) && is_string( $data->title ) )
     254                                        $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>';
    249255                                break;
    250256
Note: See TracChangeset for help on using the changeset viewer.