diff --git a/lib/domain/itunes/itunes.dart b/lib/domain/itunes/itunes.dart index 965ec20..486de06 100644 --- a/lib/domain/itunes/itunes.dart +++ b/lib/domain/itunes/itunes.dart @@ -3,6 +3,7 @@ import 'package:webfeed/domain/itunes/itunes_episode_type.dart'; import 'package:webfeed/domain/itunes/itunes_image.dart'; import 'package:webfeed/domain/itunes/itunes_owner.dart'; import 'package:webfeed/domain/itunes/itunes_type.dart'; +import 'package:webfeed/util/string.dart'; import 'package:webfeed/util/iterable.dart'; import 'package:webfeed/util/xml.dart'; import 'package:xml/xml.dart'; @@ -84,9 +85,9 @@ class Itunes { newFeedUrl: element.findElements('itunes:new-feed-url').firstOrNull?.text, block: parseBoolLiteral(element, 'itunes:block'), complete: parseBoolLiteral(element, 'itunes:complete'), - episode: episodeStr == null ? null : int.tryParse(episodeStr), - season: seasonStr == null ? null : int.tryParse(seasonStr), - duration: durationStr == null ? null : _parseDuration(durationStr), + episode: isNullOrEmpty(episodeStr) ? null : int.tryParse(episodeStr), + season: isNullOrEmpty(seasonStr) ? null : int.tryParse(seasonStr), + duration: isNullOrEmpty(durationStr) ? null : _parseDuration(durationStr), episodeType: element .findElements('itunes:episodeType') .map((e) => newItunesEpisodeType(e)) diff --git a/lib/util/string.dart b/lib/util/string.dart new file mode 100644 index 0000000..da6716f --- /dev/null +++ b/lib/util/string.dart @@ -0,0 +1,2 @@ + +bool isNullOrEmpty(String s) => s?.isEmpty ?? true; diff --git a/test/rss_test.dart b/test/rss_test.dart index f8295a0..10087db 100644 --- a/test/rss_test.dart +++ b/test/rss_test.dart @@ -371,6 +371,18 @@ void main() { expect(item.itunes!.block, false); }); + test('parse RSS-Itunes_item_empty_field.xml with empty duration field', () { + var xmlString = File('test/xml/RSS-Itunes_item_empty_field.xml').readAsStringSync(); + + var feed = RssFeed.parse(xmlString); + + expect(feed.itunes.owner.name, 'Changelog Media'); + var item = feed.items[0]; + expect(item.itunes.episodeType, ItunesEpisodeType.full); + expect(item.itunes.duration, null); + expect(item.itunes.title, 'awesome title'); + }); + test('parse RSS-RDF.xml', () { var xmlString = File('test/xml/RSS-RDF.xml').readAsStringSync(); diff --git a/test/xml/RSS-Itunes_item_empty_field.xml b/test/xml/RSS-Itunes_item_empty_field.xml new file mode 100644 index 0000000..98776a3 --- /dev/null +++ b/test/xml/RSS-Itunes_item_empty_field.xml @@ -0,0 +1,53 @@ + + + Go Time + Go Time + serial + Yes + TRUE + wubawuba + All rights reserved + https://changelog.com/gotime + + + + + en-us + + A diverse panel and special guests discuss cloud infrastructure, distributed systems, microservices, Kubernetes, Docker…oh and also Go! This show records LIVE every Thursday at 3pm US Eastern. A diverse panel and special guests discuss cloud infrastructure, distributed systems, microservices, Kubernetes, Docker…oh and also Go! + + Changelog Media + Foo + no + + go, golang, open source, software, development + + Changelog Media + editors@changelog.com + + + + + + + + + + + awesome title + full + 1 + 1 + xxx + + + no + go, golang, open source, software, development + with Erik, Carlisia, and Brian + Foo + Erik St. Martin, Carlisia Pinto, and Brian Ketelsen + + Erik St. Martin, Carlisia Pinto, and Brian Ketelsen + + + \ No newline at end of file