fix: JSON validation for unquoted @placeholders@
This commit is contained in:
@@ -35,9 +35,10 @@ export function ConfigTemplate(props: ConfigTemplateProps) {
|
||||
}
|
||||
|
||||
function handleSave() {
|
||||
// Validate JSON before saving
|
||||
// Validate JSON before saving (with placeholder support)
|
||||
try {
|
||||
JSON.parse(draftContent);
|
||||
const sanitizedValue = draftContent.replace(/@[^@]+@/g, '1');
|
||||
JSON.parse(sanitizedValue);
|
||||
setJsonError(null);
|
||||
props.onSaved(draftContent);
|
||||
setMode('view');
|
||||
@@ -52,12 +53,8 @@ export function ConfigTemplate(props: ConfigTemplateProps) {
|
||||
try {
|
||||
if (value.trim()) {
|
||||
// Replace @placeholders@ with valid JSON values for validation
|
||||
// Handle both quoted "@placeholder@" and unquoted @placeholder@
|
||||
let sanitizedValue = value
|
||||
// Replace quoted placeholders: "@host@" -> "__PLACEHOLDER__"
|
||||
.replace(/"@[^"]+@"/g, '"__PLACEHOLDER__"')
|
||||
// Replace unquoted placeholders between : and , or } : @port@ -> "__PLACEHOLDER__"
|
||||
.replace(/:\s*@[^,\s}]+@/g, ': "__PLACEHOLDER__"');
|
||||
// Strategy: Replace ALL @...@ patterns with "1" (valid for both string and numeric contexts)
|
||||
const sanitizedValue = value.replace(/@[^@]+@/g, '1');
|
||||
|
||||
JSON.parse(sanitizedValue);
|
||||
setJsonError(null);
|
||||
|
||||
Reference in New Issue
Block a user