All contributions

gookit/config

gookit/config

A Go library for loading and reading configuration from JSON, YAML, TOML, INI, environment variables and flags, with access to values by key path.

Language
Go
GitHub stars
584
Merged changes
1

What we changed

A negative index in a key path, such as arr.-1, no longer panics in GetValue or Exists and is reported as not found.

What this work shows

  • Index bounds checking in Go
  • Hardening against user input
  • Panic tests in Go
What was broken

arr.-1 crashed the program

GetValue("arr.-1") and Exists("arr.-1") ended in an index out of range [-1] panic. strconv.Atoi accepts "-1", and the checks in read.go only tested the upper bound of the slice.

How we fixed it

A lower bound in six places

We added an i < 0 check to every index guard for []int, []string and []any in GetValue and Exists, so a negative index means no value. A test checks that both calls do not panic and report not found.

#221

Merged change 1

  1. #221 fix(read): prevent panic on negative slice index in a key path Merged 7 September 2026

What it taught us

Key paths often come from users or from configuration, so every index taken from one must be checked on both sides before use. A missing lower bound was enough for a single minus sign to crash the whole program.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.