From 989f0ce41db432c70038075f0c72aa3a9b560458 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 27 May 2023 11:40:34 +0200 Subject: [PATCH] fix MFM fg/bg color regex CSS colors are either 3 or 6 hex digits, not 3 to 6 (which would allow 4 and 5 digit hex codes, which are not accepted). Also adds an explicit null/undefined check. Changes the default color for the $[bg ] function to something different than the fg color so if you use both functions on a piece of text with default values, the text stays somewhat readable. --- packages/client/src/components/mfm.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index 40b11535f..2d04a9731 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -197,14 +197,14 @@ export default defineComponent({ break; } case 'fg': { - let color = token.props.args.color; - if (!/^[0-9a-f]{3,6}$/i.test(color)) color = 'f00'; + let color = token.props.args.color ?? 'f00'; + if (!/^([0-9a-f]{3}){1,2}$/i.test(color)) color = 'f00'; style = `color: #${color};`; break; } case 'bg': { - let color = token.props.args.color; - if (!/^[0-9a-f]{3,6}$/i.test(color)) color = 'f00'; + let color = token.props.args.color ?? '0f0'; + if (!/^([0-9a-f]{3}){1,2}$/i.test(color)) color = '0f0'; style = `background-color: #${color};`; break; }