fix: Make _data field matching more specific to prevent false positives

Fix overly broad condition that matched any field containing '_data',
causing false positives and inconsistent key transformation.

Problem:
- Condition 'key.endsWith('_data') || key.includes('_data')' matches any
  field containing '_data' anywhere (e.g., 'meta_data_field', 'custom_data_config')
- key.replace(/_data$/, '') only removes '_data' from end, making logic inconsistent
- Fields with '_data' in middle get matched but key isn't transformed
- If their value happens to be valid JSON, it gets incorrectly parsed

Solution:
- Remove 'key.includes('_data')' clause
- Only check 'key.endsWith('_data')' to match actual _data suffix pattern
- Ensures consistent matching: only fields ending with '_data' are treated
  as JSON data fields, and only those get the suffix removed
- Prevents false positives on fields like 'meta_data_field' that happen to
  contain '_data' in their name
This commit is contained in:
Chuck
2026-01-08 15:30:42 -05:00
parent 37eaafe788
commit 36f948affc

View File

@@ -2223,7 +2223,8 @@ function handlePluginConfigSubmit(e) {
// Process form data with type conversion (using dot notation for nested fields) // Process form data with type conversion (using dot notation for nested fields)
for (const [key, value] of formData.entries()) { for (const [key, value] of formData.entries()) {
// Check if this is a patternProperties or array-of-objects hidden input (contains JSON data) // Check if this is a patternProperties or array-of-objects hidden input (contains JSON data)
if (key.endsWith('_data') || key.includes('_data')) { // Only match keys ending with '_data' to avoid false positives like 'meta_data_field'
if (key.endsWith('_data')) {
try { try {
const baseKey = key.replace(/_data$/, ''); const baseKey = key.replace(/_data$/, '');
const jsonValue = JSON.parse(value); const jsonValue = JSON.parse(value);