Skip to content

Normalize decimal integer and exit-code validation #158

Description

@codeforester

Problem

Several stdlib numeric contracts accept decimal-looking strings but pass them directly to Bash arithmetic, where a leading zero selects octal interpretation.

At main commit a107134:

  • n=08; assert_integer_range n 0 10 prints an arithmetic error and then returns success.
  • exit_if_error 08 message prints an arithmetic error and continues instead of exiting.
  • assert_arg_count 08 0 10 can also continue after an arithmetic error.
  • assert_integer_range value 10 1 treats an inverted range as an ordinary out-of-range value instead of invalid helper usage.

Validation helpers must never turn malformed arithmetic into a successful guard.

Scope

  • Normalize accepted integer strings to base-10 before arithmetic, including signs and leading zeros.
  • Validate that range minimum is not greater than maximum.
  • Require argument counts and bounds to be non-negative where the API represents counts.
  • Validate exit_if_error statuses as decimal shell exit codes and define handling outside 0..255.

Acceptance Criteria

  • 08, 09, +08, and -08 are handled as decimal values where signed integers are accepted.
  • No accepted numeric input emits a Bash arithmetic syntax error.
  • Invalid ranges and exit codes fail through library diagnostics rather than continuing.
  • Existing valid integer and status behavior remains unchanged.

Validation

  • bats lib/bash/std/tests/lib_std.bats
  • ./tests/validate.sh
  • git diff --check

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions