Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit 8f05896

Browse files
committed
get feed URL and use that to resolve URL if link is empty
1 parent 46735ab commit 8f05896

3 files changed

Lines changed: 3797 additions & 1 deletion

File tree

Sources/ObjC/RSRSSParser.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,18 @@ - (NSString *)urlString:(NSString *)s {
300300
}
301301

302302
if (!self.link) {
303-
//TODO: get feed URL and use that to resolve URL.*/
303+
NSURL *feedURL = [NSURL URLWithString:self.urlString];
304+
if (!feedURL) {
305+
return s;
306+
}
307+
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", feedURL.scheme, feedURL.host]];
308+
if (!baseURL) {
309+
return s;
310+
}
311+
NSURL *resolvedURL = [NSURL URLWithString:s relativeToURL:baseURL];
312+
if (resolvedURL.absoluteString) {
313+
return resolvedURL.absoluteString;
314+
}
304315
return s;
305316
}
306317

Tests/RSParserTests/RSSParserTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,13 @@ class RSSParserTests: XCTestCase {
185185
// XCTAssertNotNil(article.contentHTML)
186186
// }
187187
// }
188+
189+
func testFeedWithHomeEmpty() {
190+
let d = parserData("fuli51", "html", "https://www.fuli51.net/feed")
191+
let parsedFeed = try? FeedParser.parse(d)
192+
193+
for article in parsedFeed?.items ?? [] {
194+
XCTAssertTrue(article.url?.starts(with: "https://www.fuli51.net") ?? false )
195+
}
196+
}
188197
}

0 commit comments

Comments
 (0)