fix #46 removes quotes around hex, hopefully

This commit is contained in:
7w1 committed 2026-03-01 16:33:59 -06:00
1 parent e05ba70439
commit 81bf4ffdd8
3 files changed
+20 -5

No files matched your search

+1
View File
@@ -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
@@ -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 = () => {
+6 -1
View File
@@ -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 = (