Author: as Date: Mon Feb 18 10:45:46 2008 New Revision: 7398 Log: - Unrecognized module elements will be ignored when parsing feeds.
Modified: trunk/Feed/src/interfaces/module.php trunk/Feed/src/modules/content_module.php trunk/Feed/src/modules/dublincore_module.php trunk/Feed/tests/feed_test.php Modified: trunk/Feed/src/interfaces/module.php ============================================================================== --- trunk/Feed/src/interfaces/module.php [iso-8859-1] (original) +++ trunk/Feed/src/interfaces/module.php [iso-8859-1] Mon Feb 18 10:45:46 2008 @@ -54,7 +54,7 @@ */ public function __set( $name, $value ) { - if ( isset( $this->schema[$this->level][$name] ) ) + if ( $this->isElementAllowed( $name ) ) { $node = $this->add( $name ); $node->set( $value ); @@ -74,7 +74,7 @@ */ public function __get( $name ) { - if ( isset( $this->schema[$this->level][$name] ) ) + if ( $this->isElementAllowed( $name ) ) { return $this->properties[$name]; } @@ -93,7 +93,7 @@ */ public function __isset( $name ) { - if ( isset( $this->schema[$this->level][$name] ) ) + if ( $this->isElementAllowed( $name ) ) { return isset( $this->properties[$name] ); } @@ -101,6 +101,18 @@ { return false; } + } + + /** + * Returns true if the element $name is allowed in the current module at the + * current level (feed or item), and false otherwise. + * + * @param string $name The element name to check if allowed in the current module and level (feed or item) + * @return bool + */ + public function isElementAllowed( $name ) + { + return isset( $this->schema[$this->level][$name] ); } /** @@ -115,7 +127,7 @@ */ public function add( $name ) { - if ( isset( $this->schema[$this->level][$name] ) ) + if ( $this->isElementAllowed( $name ) ) { $node = new ezcFeedElement( $this->schema[$this->level][$name] ); $this->properties[$name][] = $node; Modified: trunk/Feed/src/modules/content_module.php ============================================================================== --- trunk/Feed/src/modules/content_module.php [iso-8859-1] (original) +++ trunk/Feed/src/modules/content_module.php [iso-8859-1] Mon Feb 18 10:45:46 2008 @@ -47,10 +47,6 @@ protected $schema = array( 'feed' => array(), 'item' => array( 'encoded' => array( '#' => 'string' ), - 'encoding' => array( '#' => 'string' ), // not supported - 'format' => array( '#' => 'string' ), // not supported - 'item' => array( '#' => 'string' ), // not supported - 'items' => array( '#' => 'string' ), // not supported ) ); /** @@ -100,14 +96,17 @@ */ public function parse( $name, $node ) { - $element = $this->add( $name ); - $value = $node->textContent; + if ( $this->isElementAllowed( $name ) ) + { + $element = $this->add( $name ); + $value = $node->textContent; - switch ( $name ) - { - case 'encoded': - $element->set( htmlspecialchars_decode( $value, ENT_NOQUOTES ) ); - break; + switch ( $name ) + { + case 'encoded': + $element->set( htmlspecialchars_decode( $value, ENT_NOQUOTES ) ); + break; + } } } Modified: trunk/Feed/src/modules/dublincore_module.php ============================================================================== --- trunk/Feed/src/modules/dublincore_module.php [iso-8859-1] (original) +++ trunk/Feed/src/modules/dublincore_module.php [iso-8859-1] Mon Feb 18 10:45:46 2008 @@ -200,30 +200,33 @@ */ public function parse( $name, $node ) { - $element = $this->add( $name ); - $value = $node->textContent; - - switch ( $name ) + if ( $this->isElementAllowed( $name ) ) { - case 'date': - $element->set( ezcFeedTools::prepareDate( $value ) ); - break; - - default: - $element->set( $value ); - } - - foreach ( ezcFeedTools::getAttributes( $node ) as $attr => $value ) - { - switch ( $attr ) + $element = $this->add( $name ); + $value = $node->textContent; + + switch ( $name ) { - case 'lang': - $element->language = $value; + case 'date': + $element->set( ezcFeedTools::prepareDate( $value ) ); break; default: - $element->$attr = $value; - break; + $element->set( $value ); + } + + foreach ( ezcFeedTools::getAttributes( $node ) as $attr => $value ) + { + switch ( $attr ) + { + case 'lang': + $element->language = $value; + break; + + default: + $element->$attr = $value; + break; + } } } } Modified: trunk/Feed/tests/feed_test.php ============================================================================== --- trunk/Feed/tests/feed_test.php [iso-8859-1] (original) +++ trunk/Feed/tests/feed_test.php [iso-8859-1] Mon Feb 18 10:45:46 2008 @@ -168,6 +168,22 @@ $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); } + public function testParseContentModuleElementNotRecognized() + { + $feed = ezcFeed::parseContent( '<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><entry><content:unsupported_element>Content</content:unsupported_element></entry></feed>' ); + $this->assertEquals( 'ezcFeed', get_class( $feed ) ); + $this->assertEquals( 'atom', $feed->getFeedType() ); + $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); + } + + public function testParseDCModuleElementNotRecognized() + { + $feed = ezcFeed::parseContent( '<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><entry><dc:unsupported_element>Content</dc:unsupported_element></entry></feed>' ); + $this->assertEquals( 'ezcFeed', get_class( $feed ) ); + $this->assertEquals( 'atom', $feed->getFeedType() ); + $this->assertEquals( 'application/atom+xml', $feed->getContentType() ); + } + public function testParseAtom1() { $dot = DIRECTORY_SEPARATOR; -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components