Recover from feed XML parsing error

This commit is contained in:
D. Berge
2021-09-04 02:43:58 +02:00
parent 29b3c9a250
commit a82fc7bc8a

View File

@@ -82,9 +82,23 @@ export default {
return data; return data;
}, },
/** Try to fix idiosyncrasies and XML bugs in the source.
*/
fixText (text) {
// Of course this will fail if there happens to be an </hr>
// element in the source.
return text.replace(/(<hr( [^>]*)?>)/g, "$1</hr>")
},
async refresh () { async refresh () {
const text = await this.api([`/rss/?remote=${atob(this.$route.params.source)}`, {text:true}]); const text = await this.api([`/rss/?remote=${atob(this.$route.params.source)}`, {text:true}]);
this.feed = this.parse(text); try {
this.feed = this.parse(text);
} catch (err) {
// If it failed to parse, try once again with some
// tweaks to address known feed bugs.
this.feed = this.parse(this.fixText(text));
}
}, },
...mapActions(["api"]) ...mapActions(["api"])