Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
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);
Fixed in r19031 - thanks for reporting!