Fix HTTP scheme for RSS Feed links
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
- (NSString *)rsxml_stringByDecodingHTMLEntities;
|
||||
- (nonnull NSString *)rsxml_md5HashString;
|
||||
- (nullable NSString *)absoluteURLWithBase:(nonnull NSURL *)baseURL;
|
||||
- (nullable NSString *)absoluteURLWithBase:(nullable NSURL *)baseURL;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -51,8 +51,11 @@
|
||||
return [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]];
|
||||
}
|
||||
|
||||
- (NSString *)absoluteURLWithBase:(NSURL *)baseURL {
|
||||
if (baseURL && ![[self lowercaseString] hasPrefix:@"http"]) {
|
||||
- (NSString *)absoluteURLWithBase:(nullable NSURL *)baseURL {
|
||||
// Update links that have no scheme.
|
||||
if (![[NSURL URLWithString:self] scheme]) {
|
||||
// baseURL is only nil for feed links, not for article links!
|
||||
if (!baseURL) baseURL = [NSURL URLWithString:@"http://"];
|
||||
NSURL *resolvedURL = [NSURL URLWithString:self relativeToURL:baseURL];
|
||||
if (resolvedURL.absoluteString) {
|
||||
return resolvedURL.absoluteString;
|
||||
|
||||
@@ -191,7 +191,7 @@ static NSString *kRDFAboutKey = @"rdf:about";
|
||||
switch (len) {
|
||||
case 4:
|
||||
if (EqualBytes(localName, "link", 4)) {
|
||||
self.parsedFeed.link = SAXParser.currentStringWithTrimmedWhitespace;
|
||||
self.parsedFeed.link = [SAXParser.currentStringWithTrimmedWhitespace absoluteURLWithBase:nil];
|
||||
self.baseURL = [NSURL URLWithString:self.parsedFeed.link];
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -287,6 +287,14 @@
|
||||
XCTAssertEqualObjects(error.localizedDescription, @"Opening and ending tag mismatch: channel line 0 and rss");
|
||||
}
|
||||
|
||||
- (void)testHttpSchemePrepending {
|
||||
NSError *error = nil;
|
||||
RSXMLData *xmlData = [self xmlFile:@"ccc-media" extension:@"rdf"];
|
||||
RSParsedFeed *parsedFeed = [[xmlData getParser] parseSync:&error];
|
||||
XCTAssertNil(error);
|
||||
XCTAssertEqualObjects(parsedFeed.link, @"http://media.ccc.de/");
|
||||
}
|
||||
|
||||
- (void)testDownloadedFeeds {
|
||||
NSError *error = nil;
|
||||
int i = 0;
|
||||
|
||||
2564
RSXMLTests/Resources/ccc-media.rdf
Normal file
2564
RSXMLTests/Resources/ccc-media.rdf
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user