Преглед изворни кода

Checking for empty String when parsing duration, episode and season in itunes.dart.

master
Pär Dahlberg пре 5 година
родитељ
комит
4c3ee0a40f
5 измењених фајлова са 72 додато и 4 уклоњено
  1. +4
    -3
      lib/domain/itunes/itunes.dart
  2. +2
    -0
      lib/util/string.dart
  3. +1
    -1
      pubspec.yaml
  4. +12
    -0
      test/rss_test.dart
  5. +53
    -0
      test/xml/RSS-Itunes_item_empty_field.xml

+ 4
- 3
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/xml.dart';
import 'package:xml/xml.dart';

@@ -73,9 +74,9 @@ class Itunes {
newFeedUrl: findFirstElement(element, 'itunes:new-feed-url')?.text,
block: parseBoolLiteral(element, 'itunes:block'),
complete: parseBoolLiteral(element, 'itunes:complete'),
episode: episodeStr == null ? null : int.parse(episodeStr),
season: seasonStr == null ? null : int.parse(seasonStr),
duration: durationStr == null ? null : _parseDuration(durationStr),
episode: isNullOrEmpty(episodeStr) ? null : int.parse(episodeStr),
season: isNullOrEmpty(seasonStr) ? null : int.parse(seasonStr),
duration: isNullOrEmpty(durationStr) ? null : _parseDuration(durationStr),
episodeType:
newItunesEpisodeType(findFirstElement(element, 'itunes:episodeType')),
);


+ 2
- 0
lib/util/string.dart Прегледај датотеку

@@ -0,0 +1,2 @@

bool isNullOrEmpty(String s) => s?.isEmpty ?? true;

+ 1
- 1
pubspec.yaml Прегледај датотеку

@@ -1,5 +1,5 @@
name: webfeed
version: 0.6.0
version: 0.6.1
description: webfeed is a dart package for parsing RSS and Atom feeds. Media, DublinCore, iTunes, Syndication namespaces are also supported.
homepage: https://github.com/witochandra/webfeed
environment:


+ 12
- 0
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();



+ 53
- 0
test/xml/RSS-Itunes_item_empty_field.xml Прегледај датотеку

@@ -0,0 +1,53 @@
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0" nighteye="disabled">
<channel>
<title>Go Time</title>
<itunes:title>Go Time</itunes:title>
<itunes:type>serial</itunes:type>
<itunes:block>Yes</itunes:block>
<itunes:complete>TRUE</itunes:complete>
<itunes:new-feed-url>wubawuba</itunes:new-feed-url>
<copyright>All rights reserved</copyright>
<link>https://changelog.com/gotime</link>
<atom:link href="https://changelog.com/gotime/feed" rel="self" type="application/rss+xml"/>
<atom:link href="https://changelog.com/gotime/feed" rel="first" type="application/rss+xml"/>
<atom:link href="https://changelog.com/gotime/feed?page=1" rel="last" type="application/rss+xml"/>
<atom:link href="https://changelog.com/gotime" rel="alternate" type="text/html"/>
<language>en-us</language>
<description>
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!
</description>
<itunes:author>Changelog Media</itunes:author>
<itunes:summary>Foo</itunes:summary>
<itunes:explicit>no</itunes:explicit>
<itunes:image href="https://cdn.changelog.com/uploads/covers/go-time-original.png?v=63725770357"/>
<itunes:keywords>go, golang, open source, software, development</itunes:keywords>
<itunes:owner>
<itunes:name>Changelog Media</itunes:name>
<itunes:email>editors@changelog.com</itunes:email>
</itunes:owner>
<itunes:category text="Technology">
<itunes:category text="Software How-To"/>
<itunes:category text="Tech News"/>
</itunes:category>
<itunes:category text="Foo">
<itunes:category text="Bar"/>
<itunes:category text="Baz"/>
</itunes:category>
<item>
<itunes:title>awesome title</itunes:title>
<itunes:episodeType>full</itunes:episodeType>
<itunes:episode>1</itunes:episode>
<itunes:season>1</itunes:season>
<itunes:block>xxx</itunes:block>
<itunes:image href="https://cdn.changelog.com/uploads/covers/go-time-original.png?v=63725770357"/>
<itunes:duration></itunes:duration>
<itunes:explicit>no</itunes:explicit>
<itunes:keywords>go, golang, open source, software, development</itunes:keywords>
<itunes:subtitle>with Erik, Carlisia, and Brian</itunes:subtitle>
<itunes:summary>Foo</itunes:summary>
<dc:creator>Erik St. Martin, Carlisia Pinto, and Brian Ketelsen
</dc:creator>
<itunes:author>Erik St. Martin, Carlisia Pinto, and Brian Ketelsen</itunes:author>
</item>
</channel>
</rss>

Loading…
Откажи
Сачувај