From 81bf4ffdd87d5c8e28aca0dc70d5d6f0dc382c80 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sun, 1 Mar 2026 16:33:59 -0600 Subject: [PATCH] fix #46 removes quotes around hex, hopefully --- CHANGELOG.md | 1 + .../settings/account/NameColorEditor.tsx | 17 +++++++++++++---- src/app/hooks/useUserProfile.ts | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02388b05..c1e6bdf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed/updated unknown extended profile keys rendering. - Added support for `---`, `-#`, and fixed `-` to be unordered. +- Fix quotes around colors for tuwunel homeservers ([#46](https://github.com/7w1/sable/issues/46)) ## 1.2.1 diff --git a/src/app/features/settings/account/NameColorEditor.tsx b/src/app/features/settings/account/NameColorEditor.tsx index 4f3da4fc..b9822d33 100644 --- a/src/app/features/settings/account/NameColorEditor.tsx +++ b/src/app/features/settings/account/NameColorEditor.tsx @@ -10,18 +10,27 @@ type NameColorEditorProps = { }; export function NameColorEditor({ current, onSave }: NameColorEditorProps) { - const [tempColor, setTempColor] = useState(current || '#FFFFFF'); + const stripQuotes = (str?: string) => { + if (!str) return ''; + // to solve the silly tuwunel + return str.replace(/^["']|["']$/g, ''); + }; + + const [tempColor, setTempColor] = useState(stripQuotes(current) || '#FFFFFF'); const [hasChanged, setHasChanged] = useState(false); useEffect(() => { - if (current) setTempColor(current); + const sanitized = stripQuotes(current); + if (sanitized) setTempColor(sanitized); else setTempColor('#FFFFFF'); }, [current]); const handleUpdate = (newColor: string) => { - const sanitized = newColor.startsWith('#') ? newColor : `#${newColor}`; + let sanitized = stripQuotes(newColor); + sanitized = sanitized.startsWith('#') ? sanitized : `#${sanitized}`; setTempColor(sanitized); - setHasChanged(sanitized.toUpperCase() !== (current?.toUpperCase() || '#FFFFFF')); + const currentSanitized = stripQuotes(current) || '#FFFFFF'; + setHasChanged(sanitized.toUpperCase() !== currentSanitized.toUpperCase()); }; const handleSave = () => { diff --git a/src/app/hooks/useUserProfile.ts b/src/app/hooks/useUserProfile.ts index 9a419c84..75db1e72 100644 --- a/src/app/hooks/useUserProfile.ts +++ b/src/app/hooks/useUserProfile.ts @@ -56,7 +56,12 @@ const normalizeInfo = (info: any): UserProfile => { }; }; -const isValidHex = (c: string) => /^#[0-9A-F]{6}$/i.test(c); +const isValidHex = (c: any): string | undefined => { + if (typeof c !== 'string') return undefined; + // silly tuwunel smh + const cleaned = c.replace(/["']/g, '').trim(); + return /^#([0-9A-F]{3,6})$/i.test(cleaned) ? cleaned : undefined; +}; const sanitizeFont = (f: string) => f.replace(/[;{}<>]/g, '').slice(0, 32); export const useUserProfile = (