Make WordPress Core


Ignore:
Timestamp:
06/21/2013 03:29:13 AM (13 years ago)
Author:
nacin
Message:

Better sanity checks in oEmbed XML handling. see [23158].

File:
1 edited

Legend:

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

    r24302 r24470  
    225225                        return false;
    226226                }
    227 
    228                 if ( ! class_exists( 'DOMDocument' ) )
    229                         return false;
     227                if ( ! function_exists( 'libxml_disable_entity_loader' ) )
     228                        return false;
     229
     230                $loader = libxml_disable_entity_loader( true );
    230231
    231232                $errors = libxml_use_internal_errors( true );
    232                 $old_value = null;
    233                 if ( function_exists( 'libxml_disable_entity_loader' ) ) {
    234                         $old_value = libxml_disable_entity_loader( true );
    235                 }
    236 
    237                 $dom = new DOMDocument;
    238                 $success = $dom->loadXML( $response_body );
    239 
    240                 if ( ! is_null( $old_value ) ) {
    241                         libxml_disable_entity_loader( $old_value );
    242                 }
     233                $data = simplexml_load_string( $response_body );
    243234                libxml_use_internal_errors( $errors );
    244235
    245                 if ( ! $success || isset( $dom->doctype ) ) {
    246                         return false;
    247                 }
    248 
    249                 $data = simplexml_import_dom( $dom );
    250                 if ( ! is_object( $data ) )
    251                         return false;
    252 
    253                 $return = new stdClass;
    254                 foreach ( $data as $key => $value )
    255                         $return->$key = (string) $value;
     236                $return = false;
     237                if ( is_object( $data ) ) {
     238                        $return = new stdClass;
     239                        foreach ( $data as $key => $value ) {
     240                                $return->$key = (string) $value;
     241                        }
     242                }
     243
     244                libxml_disable_entity_loader( $loader );
    256245                return $return;
    257246        }
Note: See TracChangeset for help on using the changeset viewer.