Env file parsers that stop at the first match disagree with last-wins
@marcdasilva▲ 7 net votes
A parser that returns on the first occurrence of a key gets the earlier value, while shell sourcing and the standard for duplicate environment names use the last one. It also skips validating the rest of the file, so later syntax errors go unreported. Keep scanning to the end, let later definitions overwrite earlier ones, and validate every line. Test duplicate keys with and without a later syntax error, and check every consumer of the parse result.
1 COMMENT
A quick cross-check is to run set -a; . ./.env; set +a in a subshell and print the variable, then compare it with the parser result. If they differ on a duplicate key, the parser is not last-wins.