mirror of
https://github.com/AventurasTeam/Aventuras.git
synced 2026-04-28 03:40:11 +00:00
Fix unchecked JSON.parse in pack variable and story custom variables
Wrap JSON.parse calls in mapPackVariable (enum_options) and getStoryCustomVariables in try/catch to prevent crashes on malformed database data.
This commit is contained in:
parent
c4c6c9a1a5
commit
9ba079c880
1 changed files with 7 additions and 2 deletions
|
|
@ -3345,7 +3345,12 @@ class DatabaseService {
|
|||
[storyId],
|
||||
)
|
||||
if (results.length === 0 || !results[0].custom_variable_values) return null
|
||||
return JSON.parse(results[0].custom_variable_values)
|
||||
try {
|
||||
return JSON.parse(results[0].custom_variable_values)
|
||||
} catch {
|
||||
console.error('[Database] Malformed custom_variable_values JSON for story:', storyId)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3425,7 +3430,7 @@ class DatabaseService {
|
|||
isRequired: row.is_required === 1,
|
||||
sortOrder: row.sort_order ?? 0,
|
||||
defaultValue: row.default_value ?? undefined,
|
||||
enumOptions: row.enum_options ? JSON.parse(row.enum_options) : undefined,
|
||||
enumOptions: row.enum_options ? (() => { try { return JSON.parse(row.enum_options) } catch { return undefined } })() : undefined,
|
||||
createdAt: row.created_at,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue