mirror of https://github.com/readrops/Readrops.git
Replace RSS2 atom:link element value by response url, as atom:link element is unreliable
This commit is contained in:
parent
7eecbc8e8b
commit
872a894db0
|
@ -32,7 +32,7 @@ class LocalRSSDataSourceTest {
|
|||
|
||||
@Before
|
||||
fun before() {
|
||||
mockServer.start()
|
||||
mockServer.start(8080)
|
||||
url = mockServer.url("/rss")
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ class LocalRSSDataSourceTest {
|
|||
val feed = pair?.first!!
|
||||
|
||||
assertEquals(feed.name, "Hacker News")
|
||||
assertEquals(feed.url, "http://localhost:8080/rss")
|
||||
assertEquals(feed.siteUrl, "https://news.ycombinator.com/")
|
||||
assertEquals(feed.description, "Links for the intellectually curious, ranked by readers.")
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
|||
val adapter = Moshi.Builder()
|
||||
.add(JSONFeedAdapter())
|
||||
.build()
|
||||
.adapter<Feed>(Feed::class.java)
|
||||
.adapter(Feed::class.java)
|
||||
|
||||
adapter.fromJson(Buffer().readFrom(stream))!!
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
|
|||
private fun handleSpecialCases(feed: Feed, type: LocalRSSHelper.RSSType, response: Response) {
|
||||
with(feed) {
|
||||
if (type == LocalRSSHelper.RSSType.RSS_2) {
|
||||
if (url == null) url = response.request.url.toString()
|
||||
// if an atom:link element was parsed, we still replace its value as it is unreliable,
|
||||
// otherwise we just add the rss url
|
||||
url = response.request.url.toString()
|
||||
} else if (type == LocalRSSHelper.RSSType.ATOM) {
|
||||
if (url == null) url = response.request.url.toString()
|
||||
if (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host
|
||||
|
|
Loading…
Reference in New Issue