compose-spec / compose-go

Reference library for parsing and loading Compose YAML files
https://compose-spec.io
Apache License 2.0
355 stars 112 forks source link

WithOsEnv assumes wrongly that os.Environ() returns only strings containing an equal sign #639

Closed apostasie closed 3 months ago

apostasie commented 4 months ago

https://github.com/compose-spec/compose-go/blob/main/cli/options.go#L240

This will call GetAsEqualsMap which will throw with an index out of bound in case a string does not contain an equal sign.

(we did hit that with a broken test in nerdctl - https://github.com/containerd/nerdctl/pull/3111)

ndeloof commented 3 months ago

In which circumstances does os.Envrion not return an equals sign? That's not clearly described by https://pkg.go.dev/os#Environ

apostasie commented 3 months ago

Thanks for fixing this @ndeloof

FWIW, a quick repro here: https://go.dev/play/p/JQw_6OA2--s

ndeloof commented 3 months ago

sure, but I wonder in which real circumstances os.Environ() would return a string without = sign.

apostasie commented 3 months ago

sure, but I wonder in which real circumstances os.Environ() would return a string without = sign.

I see your point. Agreed that it "should not happen under real/normal circumstances" (tm) :-).