Fix Simple Mapping to use proper UUIDs for mapping IDs

- Add generateUUID() function using crypto.randomUUID() with fallback
- Update handleAdd to use UUID instead of Date.now() + Math.random()
- UUIDs are now properly validated in backend to prevent injection
- mapping_id is persisted when creating mapping pairs for reuse

Co-authored-by: Koha9 <36852125+Koha9@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-03 12:44:27 +00:00
parent fbafe75fae
commit 6a1780bcee
+15 -1
View File
@@ -22,6 +22,20 @@ import {
Code2 Code2
} from 'lucide-react'; } from 'lucide-react';
// Generate a UUID for mapping rules
const generateUUID = (): string => {
// Use crypto.randomUUID() if available (modern browsers)
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}
// Fallback to manual UUID v4 generation
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
interface StrategyOption { interface StrategyOption {
value: SyncStrategy; value: SyncStrategy;
label: string; label: string;
@@ -137,7 +151,7 @@ const MappingGroupEditor: React.FC<MappingGroupEditorProps> = ({
const handleAdd = () => { const handleAdd = () => {
if (isLocked) return; if (isLocked) return;
const newId = Date.now().toString() + Math.random().toString(); const newId = generateUUID();
onChange([...rules, { id: newId, search: '', replace: '' }]); onChange([...rules, { id: newId, search: '', replace: '' }]);
}; };