Skip to content

Fixes an issue with array based fields when saving from the web UI#49

Merged
infinition merged 2 commits into
infinition:mainfrom
afreeland:afreeland/fix-web-save-for-arrays
Nov 19, 2024
Merged

Fixes an issue with array based fields when saving from the web UI#49
infinition merged 2 commits into
infinition:mainfrom
afreeland:afreeland/fix-web-save-for-arrays

Conversation

@afreeland

@afreeland afreeland commented Nov 18, 2024

Copy link
Copy Markdown
Contributor

This PR fixes a potential issue when a user clicks "Save" from the web UI and can null out empty array fields or even change types (ie: Array to String).

In my case I had only a single mac_scan_blacklist value, the mac address of the Bjorn device itself. When the UI presented this value xx:xx:xx:xx it did not include a , character and was being skipped by the check value.includes(',') in config.js.

The code now tracks known array fields and will either test if the value includes a , or if the form field is a known array type. This will allow the array based form fields to hit the same logic path and keep the data type accurate and consistent.

image

I could verify this change by grepping the shared_config.json and watching the "Save" turn the config into this:

 cat ../../config/shared_config.json | grep "blacklist"
    "blacklistcheck": true,
    "mac_scan_blacklist": "xx:xx:xx:xx:xx:d8",
    "ip_scan_blacklist": "null",

Then after the code fix

cat ../../config/shared_config.json | grep "blacklist" -A3
    "blacklistcheck": true,
    "displaying_csv": true,
    "log_debug": true,
    "log_info": true,
--
    "mac_scan_blacklist": [
        "xx:xx:xx:xx:xx:d8"
    ],
    "ip_scan_blacklist": [
        "null"
    ],
    "steal_file_names": [

@afreeland afreeland mentioned this pull request Nov 18, 2024
@afreeland

afreeland commented Nov 19, 2024

Copy link
Copy Markdown
Contributor Author

Also added a 2nd commit that will handle the case where a user wants to clear out a value, that otherwise would've came in as "" or null and then get persisted into the config.

The web behavior will now return early if the user input form data is "". Previously if that occurred it would fail and get nulled out from the NaN checks and parseFloat. When the utils goes to leverage this data any list type value will now kick any empty "" strings so they do not get persisted in the shared_config.json.

@infinition infinition left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good @afreeland thanks

@infinition infinition merged commit 119dd19 into infinition:main Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants