From 502fb7256aa744957f16a635f831c475682a9e20 Mon Sep 17 00:00:00 2001 From: dangered wolf <d@ngeredwolf.me> Date: Thu, 14 Jul 2022 18:35:08 -0400 Subject: [PATCH] Fixed escaping of tweet in meta tags --- src/status.ts | 5 +++-- src/utils.ts | 12 +++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/status.ts b/src/status.ts index dc1c58c..b1808f8 100644 --- a/src/status.ts +++ b/src/status.ts @@ -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"/>` ); } diff --git a/src/utils.ts b/src/utils.ts index f041ce1..3343bd1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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, '"').replace(/\</g, '<').replace(/\>/g, '>'); +} \ No newline at end of file