Zend Framework

Zend_Feed_Reder::import() doesn't fail on non-feed documents

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.9.6
  • Component/s: Zend_Feed_Reader
  • Labels:
    None

Description

Zend_Feed_Reader sucessfully imports non-feed documents (valid XHTML pages). I think it should throw an exception.

Code:

$feed = Zend_Feed_Reader::import('http://twitter.com/alganet');
echo $feed->getDomDocument()->documentElement->nodeName;

Output:

html

Expected:

Fatal error: Uncaught exception 'Zend_Feed_Exception' with message 'URL must point to a feed document' (...)

Workaround Sample:

$allowedMimetypes = array(
    'application/atom+xml',
    'application/rss+xml',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://twitter.com/alganet');
curl_setopt($curl, CURLOPT_HEADER, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true); //Just headers
$headers = explode("\n", curl_exec($curl));
foreach ($headers as $header) {
    $header = explode(":", $header);
    if (count($header) != 2) continue;
    if (strtolower($header[0]) == 'content-type') {
        $header[1] = trim($header[1]);
        if (!in_array($header[1], $allowedMimetypes)) {
            throw new Zend_Feed_Exception('URL must point to a feed document');
        } 
        break;
    }
}
curl_close($curl);

Activity

Hide
Pádraic Brady added a comment -

Fixed in r19031 - thanks for reporting!

Show
Pádraic Brady added a comment - Fixed in r19031 - thanks for reporting!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: