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

get feed URL and use that to resolve URL if link is empty #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the baseURL step? My thinking is that we get the resolvedURL using the feedURL, something like:

NSURL *resolvedURL = [NSURL URLWithString:s relativeToURL:feedURL];

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, but I'm not well-acquainted with the NSURL API

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