Issues

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

Issue Type: Bug Created: 2009-11-18T10:35:55.000+0000 Last Updated: 2009-11-19T05:35:26.000+0000 Status: Resolved Fix version(s): - 1.9.6 (24/Nov/09)

Reporter: Alexandre Gomes Gaigalas (alganet) Assignee: Pádraic Brady (padraic) Tags: - Zend_Feed_Reader

Related issues: Attachments:

Description

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

Code:

<pre class="highlight">
$feed = Zend_Feed_Reader::import('<a href="http://twitter.com/alganet">http://twitter.com/alganet</a>');
echo $feed->getDomDocument()->documentElement->nodeName;

Output:

<pre class="highlight">
html

Expected:

<pre class="highlight">
Fatal error: Uncaught exception 'Zend_Feed_Exception' with message 'URL must point to a feed document' (...)

Workaround Sample:

<pre class="highlight">

$allowedMimetypes = array(
    'application/atom+xml',
    'application/rss+xml',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, '<a href="http://twitter.com/alganet">http://twitter.com/alganet</a>');
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!

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts