fix(settings): support Persian and flexible SMS variable names and improve save persistence
This commit is contained in:
@@ -60,15 +60,17 @@ const sanitizeTemplateId = (value) => {
|
||||
if (value == null) return '';
|
||||
const digits = String(value).trim();
|
||||
if (!digits) return '';
|
||||
if (!/^\d{1,20}$/.test(digits)) return null;
|
||||
if (!/^\d{1,30}$/.test(digits)) return null;
|
||||
return digits;
|
||||
};
|
||||
|
||||
const sanitizeVariableName = (value) => {
|
||||
if (value == null) return '';
|
||||
const name = String(value).trim().replace(/^#+|#+$/g, '');
|
||||
const name = String(value).trim().replace(/^#+|#+$/g, '').trim();
|
||||
if (!name) return '';
|
||||
if (!/^[A-Za-z][A-Za-z0-9_]{0,49}$/.test(name)) return null;
|
||||
// Check for dangerous injection or control chars
|
||||
if (/[\r\n\t\0<>"'`]/.test(name)) return null;
|
||||
if (name.length > 100) return null;
|
||||
return name;
|
||||
};
|
||||
|
||||
@@ -144,7 +146,9 @@ const resolveVariablesList = (def, storedVariables) => {
|
||||
const slot = String(item.slot || '').trim();
|
||||
if (!slot) return null;
|
||||
const slotDef = (def?.slots || []).find((s) => s.key === slot);
|
||||
const rawName = item.name !== undefined ? item.name : slotDef?.defaultName || '';
|
||||
const rawName = item.name !== undefined && String(item.name).trim() !== ''
|
||||
? String(item.name).trim()
|
||||
: slotDef?.defaultName || '';
|
||||
const sanitized = sanitizeVariableName(rawName);
|
||||
return {
|
||||
slot,
|
||||
|
||||
Reference in New Issue
Block a user