Przeglądaj źródła

Merge pull request #39 from pdahlberg/parse_null_or_empty

Empty String check
master
Wito Chandra 5 lat temu
committed by GitHub
rodzic
commit
a1c0ba97cf
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 71 dodań i 3 usunięć
  1. +4
    -3
      lib/domain/itunes/itunes.dart
  2. +2
    -0
      lib/util/string.dart
  3. +12
    -0
      test/rss_test.dart
  4. +53
    -0
      test/xml/RSS-Itunes_item_empty_field.xml

+ 4
- 3
lib/domain/itunes/itunes.dart Wyświetl plik

@@ -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_image.dart';
import 'package:webfeed/domain/itunes/itunes_owner.dart'; import 'package:webfeed/domain/itunes/itunes_owner.dart';
import 'package:webfeed/domain/itunes/itunes_type.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/iterable.dart';
import 'package:webfeed/util/xml.dart'; import 'package:webfeed/util/xml.dart';
import 'package:xml/xml.dart'; import 'package:xml/xml.dart';
@@ -84,9 +85,9 @@ class Itunes {
newFeedUrl: element.findElements('itunes:new-feed-url').firstOrNull?.text, newFeedUrl: element.findElements('itunes:new-feed-url').firstOrNull?.text,
block: parseBoolLiteral(element, 'itunes:block'), block: parseBoolLiteral(element, 'itunes:block'),
complete: parseBoolLiteral(element, 'itunes:complete'), 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 episodeType: element
.findElements('itunes:episodeType') .findElements('itunes:episodeType')
.map((e) => newItunesEpisodeType(e)) .map((e) => newItunesEpisodeType(e))


+ 2
- 0
lib/util/string.dart Wyświetl plik

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

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

+ 12
- 0
test/rss_test.dart Wyświetl plik

@@ -371,6 +371,18 @@ void main() {
expect(item.itunes!.block, false); 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', () { test('parse RSS-RDF.xml', () {
var xmlString = File('test/xml/RSS-RDF.xml').readAsStringSync(); var xmlString = File('test/xml/RSS-RDF.xml').readAsStringSync();




+ 53
- 0
test/xml/RSS-Itunes_item_empty_field.xml Wyświetl plik

@@ -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>

Ładowanie…
Anuluj
Zapisz