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

Commit

Permalink
get feed URL and use that to resolve URL if link is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
wyy931 committed Apr 30, 2023
1 parent 46735ab commit 8f05896
Show file tree
Hide file tree
Showing 3 changed files with 3,797 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/ObjC/RSRSSParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,18 @@ - (NSString *)urlString:(NSString *)s {
}

if (!self.link) {
//TODO: get feed URL and use that to resolve URL.*/
NSURL *feedURL = [NSURL URLWithString:self.urlString];
if (!feedURL) {
return s;
}
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", feedURL.scheme, feedURL.host]];
if (!baseURL) {
return s;
}
NSURL *resolvedURL = [NSURL URLWithString:s relativeToURL:baseURL];
if (resolvedURL.absoluteString) {
return resolvedURL.absoluteString;
}
return s;
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/RSParserTests/RSSParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,13 @@ class RSSParserTests: XCTestCase {
// XCTAssertNotNil(article.contentHTML)
// }
// }

func testFeedWithHomeEmpty() {
let d = parserData("fuli51", "html", "https://www.fuli51.net/feed")
let parsedFeed = try? FeedParser.parse(d)

for article in parsedFeed?.items ?? [] {
XCTAssertTrue(article.url?.starts(with: "https://www.fuli51.net") ?? false )
}
}
}
Loading

0 comments on commit 8f05896

Please sign in to comment.