Skip to content

Enforce indexed-array contracts in list and string helpers #92

Description

@codeforester

Context

lib_list.sh and the array-oriented parts of lib_str.sh document caller-owned indexed arrays, but they currently validate only the variable name. Passing a scalar can silently coerce it into an indexed array, and passing an associative array reads values in hash order.

lib_arg.sh already has a local pattern for checking declared array kind before mutating caller-owned variables.

Scope

  • Add or reuse a standard helper for checking declared Bash array kind.
  • Require indexed arrays for list_append, list_prepend, list_remove, list_contains, list_unique, list_length, str_split, str_join, and str_in_array where the argument is documented as an array.
  • Preserve valid indexed-array behavior and in-place mutation semantics.
  • Add BATS coverage for scalar and associative-array rejection.
  • Update docs if callers must explicitly declare -a result arrays before use.

Acceptance Criteria

  • List and string array helpers reject scalar variables and associative arrays with clear diagnostics.
  • Existing valid indexed-array examples continue to pass.
  • The implementation follows existing Bash 4.2-compatible style and avoids nameref requirements.
  • ./tests/validate.sh passes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or product improvement

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions