Fix crash when libxml set error in @autoreleasepool

- libxml will return first parsing error instead of last one
- option to replace lower ascii chars with whitespace
This commit is contained in:
relikd
2019-03-06 02:05:09 +01:00
parent f9a3c1c831
commit d9b6641a99
8 changed files with 124 additions and 16 deletions

View File

@@ -265,6 +265,28 @@
#pragma clang diagnostic pop
}
- (void)testLowerAsciiCharacters {
NSError *error = nil;
RSXMLData *xmlData = [self xmlFile:@"lower-ascii" extension:@"rss"];
RSXMLParser *parser = [xmlData getParser];
RSParsedFeed *parsedFeed = [parser parseSync:&error];
XCTAssertNotNil(error);
XCTAssertEqual(parsedFeed.articles.count, 2);
parser.dontStopOnLowerAsciiBytes = YES;
parsedFeed = [parser parseSync:&error];
XCTAssertNil(error);
XCTAssertEqual(parsedFeed.articles.count, 5);
}
- (void)testBrokenXML {
NSError *error = nil;
RSXMLData *xmlData = [self xmlFile:@"broken" extension:@"rss"];
[[xmlData getParser] parseSync:&error];
XCTAssertNotNil(error);
XCTAssertEqual(error.code, 76);
XCTAssertEqualObjects(error.localizedDescription, @"Opening and ending tag mismatch: channel line 0 and rss");
}
- (void)testDownloadedFeeds {
NSError *error = nil;
int i = 0;

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Manton Reece</title>
<atom:link href="http://www.manton.org/feed" rel="self" type="application/rss+xml" />
<link>http://www.manton.org</link>
<description></description>
<lastBuildDate>Fri, 25 Sep 2015 14:26:40 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>http://wordpress.org/?v=4.2.5</generator>
<item>
<title></title>
<link>http://www.manton.org/2015/09/3071.html</link>
<comments>http://www.manton.org/2015/09/3071.html#comments</comments>
<pubDate>Fri,</pubDate>
</item>
</rss>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel>
<title>Feed Title</title>
<item>
<title>1</title>
<link>http://someurl.com/1/</link>
<description><![CDATA[Description of first]]></description>
</item>
<item>
<title>2</title>
<link>http://someurl.com/2/</link>
<description><![CDATA[Description with  NULL values]]></description>
</item>
<item>
<title>3</title>
<link>http://someurl.com/3/</link>
<description><![CDATA[Description of third]]></description>
</item>
<item>
<title>4</title>
<link>http://someurl.com/4/</link>
<description><![CDATA[Description of fourth]]></description>
</item>
<item>
<title>5</title>
<link>http://someurl.com/5/</link>
<description><![CDATA[Description of fifth]]></description>
</item>
</channel>
</rss>