diff --git a/src/Item.php b/src/Item.php index 9e97e3bb0..a5cce27b2 100644 --- a/src/Item.php +++ b/src/Item.php @@ -1458,10 +1458,10 @@ public function get_enclosures() $bitrate = $this->sanitize($content['attribs']['']['bitrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } if (isset($content['attribs']['']['channels'])) { - $channels = $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); + $channels = (int) $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } if (isset($content['attribs']['']['duration'])) { - $duration = $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); + $duration = (int) $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } else { $duration = $duration_parent; } @@ -1915,10 +1915,10 @@ public function get_enclosures() $bitrate = $this->sanitize($content['attribs']['']['bitrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } if (isset($content['attribs']['']['channels'])) { - $channels = $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); + $channels = (int) $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } if (isset($content['attribs']['']['duration'])) { - $duration = $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); + $duration = (int) $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); } else { $duration = $duration_parent; } diff --git a/tests/Unit/EnclosureTest.php b/tests/Unit/EnclosureTest.php index 29cec789a..7c6a8c83d 100644 --- a/tests/Unit/EnclosureTest.php +++ b/tests/Unit/EnclosureTest.php @@ -190,4 +190,110 @@ public static function getEnclosuresProvider(): iterable 2, ]; } + + /** + * @dataProvider getEnclosureIntAttributesProvider + */ + public function test_enclosure_int_attributes(string $data, ?int $expectedDuration, ?int $expectedChannels, ?int $expectedLength): void + { + $feed = new SimplePie(); + $feed->set_raw_data($data); + $feed->enable_cache(false); + $feed->init(); + + $item = $feed->get_item(0); + self::assertInstanceOf(Item::class, $item); + + $enclosure = $item->get_enclosure(0); + self::assertInstanceOf(Enclosure::class, $enclosure); + self::assertSame($expectedDuration, $enclosure->get_duration()); + self::assertSame($expectedChannels, $enclosure->get_channels()); + self::assertSame($expectedLength, $enclosure->get_length()); + } + + /** + * @return iterable + */ + public static function getEnclosureIntAttributesProvider(): iterable + { + yield 'Test media:content duration, channels and fileSize' => [ + << + + Test + http://example.net/ + + Test item + http://example.net/1 + + + + +XML + , + 123, + 2, + 987654, + ]; + + yield 'Test media:group media:content duration, channels and fileSize' => [ + << + + Test + http://example.net/ + + Test item + http://example.net/2 + + + + + + +XML + , + 456, + 6, + 12345678, + ]; + + yield 'Test RSS 2.0 enclosure length' => [ + << + + Test + http://example.net/ + + Test item + http://example.net/3 + + + + +XML + , + null, + null, + 55443322, + ]; + + yield 'Test Atom 1.0 enclosure length' => [ + << + Test + + + Test item + + + + +XML + , + null, + null, + 11223344, + ]; + } }