Make WordPress Core

Ticket #7456: 4779.r8544.diff

File 4779.r8544.diff, 1.5 KB (added by jacobsantos, 18 years ago)

Suppresses errors when WP_DEBUG is not enabled and returns WP_Error when malformed url. Actually, parse_url() shouldn't be used to validate urls, but oh well.

  • http.php

     
    542542
    543543                $arrURL = parse_url($url);
    544544
     545                if ( false === $arrURL )
     546                        return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
     547
    545548                if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] )
    546549                        $url = str_replace($arrURL['scheme'], 'http', $url);
    547550
    548                 $handle = fopen($url, 'r');
     551                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) )
     552                        $handle = @fopen($url, 'r');
     553                else
     554                        $handle = fopen($url, 'r');
    549555
    550556                if (! $handle)
    551557                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
     
    637643
    638644                $arrURL = parse_url($url);
    639645
     646                if ( false === $arrURL )
     647                        return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
     648
    640649                if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] )
    641650                        $url = str_replace($arrURL['scheme'], 'http', $url);
    642651
     
    656665
    657666                $context = stream_context_create($arrContext);
    658667
    659                 $handle = fopen($url, 'r', false, $context);
     668                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) )
     669                        $handle = @fopen($url, 'r');
     670                else
     671                        $handle = fopen($url, 'r');
    660672
    661673                if ( ! $handle)
    662674                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
     
    11071119        return $response['body'];
    11081120}
    11091121
    1110 ?>
    1111  No newline at end of file
     1122?>