mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
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:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user