Fix quoting

This commit is contained in:
tezlm 2023-01-23 00:58:45 -08:00
parent 0000009749
commit 0000010f63
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
2 changed files with 14 additions and 5 deletions

View file

@ -5,6 +5,7 @@
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark light">
<meta name="description" content="@excerpt">
<meta property="og:type" content="article">
<meta property="og:url" content="@url">

View file

@ -13,6 +13,14 @@ const headers = {
// "User-Agent": "AdsBot-Google (+http://www.google.com/adsbot.html)",
};
function sanitize(str) {
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
}
export default async function parse(url) {
const content = await fetch(url, { headers }).then(res => res.text()).catch(() => null);
if (content === null) return error;
@ -24,11 +32,11 @@ export default async function parse(url) {
const article = reader.parse();
return template
.replace(/@lang/g, article.lang)
.replace(/@byline/g, article.byline ? `by ${article.byline} - `: "")
.replace(/@lang/g, sanitize(article.lang))
.replace(/@byline/g, article.byline ? `by ${sanitize(article.byline)} - `: "")
.replace(/@size/g, fmtSize(article.length))
.replace(/@url/g, url)
.replace(/@title/g, article.title)
.replace(/@excerpt/g, article.excerpt)
.replace(/@url/g, sanitize(url))
.replace(/@title/g, sanitize(article.title))
.replace(/@excerpt/g, sanitize(article.excerpt))
.replace(/@body/g, dompurify.sanitize(article.content));
}