Skip to content

fix: preserve gaps in envPrefix slice indices - #437

Open
team-humaki wants to merge 1 commit into
caarlos0:mainfrom
team-humaki:fix/nonconsecutive-slice-env-indices
Open

team-humaki wants to merge 1 commit into
caarlos0:mainfrom
team-humaki:fix/nonconsecutive-slice-env-indices

Conversation

@team-humaki

Copy link
Copy Markdown

Summary

  • doParseSlice now sizes slices to maxIndex+1, preserving gaps with zero-value placeholders (issue expected behavior)
  • Indexes above maxSliceEnvIndex (1000) return SliceIndexTooLargeError to avoid huge allocations (e.g. FOO_1000000)

Fixes #435

Design note

The issue author asked whether gaps should be preserved or compacted. This PR follows the Expected Behavior in the issue (preserve indexes/gaps). Happy to adjust to compacting if maintainers prefer that instead.

Test plan

  • go test ./...
  • Regression for FOO_0 / FOO_1 / FOO_3 gap case
  • Oversized index safety case

doParseSlice previously stopped at the first missing index, so
FOO_0 / FOO_2 / FOO_3 only loaded through the gap. Scan for the max
numeric index under the prefix and size the slice to max+1, leaving
zero-value placeholders for missing indexes.

Reject indexes above maxSliceEnvIndex (1000) to avoid huge allocations.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support non‑consecutive indices when parsing slice environment variables

1 participant