Skip to content

Harden string helper arity and str_split result variables #79

Description

@codeforester

Context

Two verified string-library issues should be fixed together because both are small lib_str.sh API hardening items.

Findings

  1. str_contains, str_starts_with, and str_ends_with do not call assert_arg_count. Missing arguments silently produce misleading predicate results.
  2. str_split declares a local array named fields; if the caller also uses fields as the result array name, Bash scoping causes the assignment to hit the function-local array and the caller array remains unchanged.

Failure Scenarios

str_contains "needle-only"  # currently returns success because needle defaults to empty

fields=()
str_split fields "a:b:c" ":"  # caller array remains empty

Scope

  • Add explicit arity checks to all string predicate helpers.
  • Rename str_split internal locals to collision-resistant private names.
  • Add BATS coverage for missing predicate args and result variable names that match old internal names.

Acceptance Criteria

  • Predicate helpers fail consistently on wrong arity.
  • str_split fields ... updates the caller-owned fields array.
  • Existing string helper behavior remains unchanged for valid calls.
  • ./tests/validate.sh passes.

Validation

  • ./tests/validate.sh

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions