ZF-8328: Zend_Feed_Reder::import() doesn't fail on non-feed documents
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);
Comments
Posted by Pádraic Brady (padraic) on 2009-11-19T05:35:25.000+0000
Fixed in r19031 - thanks for reporting!