Merge pull request #1291 from glacambre/fix_getrsslinks

excmds.ts: Make sure getRssLinks() only works with string hrefs
This commit is contained in:
Oliver Blanthorn 2019-01-21 20:16:09 +00:00 committed by GitHub
commit 1692c0ccff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,23 +134,25 @@ export async function getNativeVersion(): Promise<void> {
//#content
export async function getRssLinks(): Promise<{ type: string; url: string; title: string }[]> {
let seen = new Set<string>()
return Array.from(document.querySelectorAll("a, link[rel='alternate']")).reduce((acc, e: any) => {
let type = ""
// Start by detecting type because url doesn't necessarily contain the words "rss" or "atom"
if (e.type) {
// if type doesn't match either rss or atom, don't include link
if (e.type.indexOf("rss") < 0 && e.type.indexOf("atom") < 0) return acc
type = e.type
} else {
// Making sure that we match either a dot or "xml" because "urss" and "atom" are actual words
if (e.href.match(/(\.rss)|(rss\.xml)/i)) type = "application/rss+xml"
else if (e.href.match(/(\.atom)|(atom\.xml)/i)) type = "application/atom+xml"
else return acc
}
if (seen.has(e.href)) return acc
seen.add(e.href)
return acc.concat({ type, url: e.href, title: e.title || e.innerText } as { type: string; url: string; title: string })
}, [])
return Array.from(document.querySelectorAll("a, link[rel='alternate']"))
.filter((e: any) => typeof e.href == "string")
.reduce((acc, e: any) => {
let type = ""
// Start by detecting type because url doesn't necessarily contain the words "rss" or "atom"
if (e.type) {
// if type doesn't match either rss or atom, don't include link
if (e.type.indexOf("rss") < 0 && e.type.indexOf("atom") < 0) return acc
type = e.type
} else {
// Making sure that we match either a dot or "xml" because "urss" and "atom" are actual words
if (e.href.match(/(\.rss)|(rss\.xml)/i)) type = "application/rss+xml"
else if (e.href.match(/(\.atom)|(atom\.xml)/i)) type = "application/atom+xml"
else return acc
}
if (seen.has(e.href)) return acc
seen.add(e.href)
return acc.concat({ type, url: e.href, title: e.title || e.innerText } as { type: string; url: string; title: string })
}, [])
}
/**