Fixed escaping of tweet in meta tags

This commit is contained in:
dangered wolf 2022-07-14 18:35:08 -04:00
parent 280a2d0376
commit 502fb7256a
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 6 additions and 11 deletions

View file

@ -5,6 +5,7 @@ import { linkFixer } from './linkFixer';
import { colorFromPalette } from './palette';
import { renderPoll } from './poll';
import { handleQuote } from './quote';
import { sanitizeText } from './utils';
export const handleStatus = async (
status: string,
@ -109,7 +110,7 @@ export const handleStatus = async (
`<meta name="twitter:title" content="${name} (@${screenName})"/>`,
`<meta name="twitter:image" content="0"/>`,
`<meta name="twitter:creator" content="@${name}"/>`,
`<meta content="${text}" property="og:description"/>`
`<meta content="${sanitizeText(text)}" property="og:description"/>`
);
} else {
console.log('Media available');
@ -194,7 +195,7 @@ export const handleStatus = async (
headers.push(
`<meta content="${name} (@${screenName})" property="og:title"/>`,
`<meta content="${text}" property="og:description"/>`
`<meta content="${sanitizeText(text)}" property="og:description"/>`
);
}

View file

@ -1,9 +1,3 @@
// https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
const componentToHex = (component: number) => {
let hex = component.toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
export const rgbToHex = (r: number, g: number, b: number) =>
`#${componentToHex(r)}${componentToHex(g)}${componentToHex(b)}`;
export const sanitizeText = (text: string) => {
return text.replace(/\"/g, '&#34;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;');
}