# Environ: reinstate \`null\` return on \`=\` in environment variable keys · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/bcb5218a2b2bce189831e68b3396cfd6f246caa2)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: bcb5218a2b2bce189831e68b3396cfd6f246caa2

Requested commit: bcb5218a2b2bce189831e68b3396cfd6f246caa2

Commit: bcb5218a2b2bce189831e68b3396cfd6f246caa2

Tree: 79d594257171e1a93b71f81612254bbcc8d4a77d

Author: Ryan Liptak

Committer: Andrew Kelley

## Message

```
Environ: reinstate `null` return on `=` in environment variable keys

Changes an assert back into a conditional to match the behavior of `getPosix`, see https://codeberg.org/ziglang/zig/pulls/31113#issuecomment-10371698 and https://github.com/ziglang/zig/issues/23331.
Note: the conditional has been updated to also return null early on 0-length key lookups, since there's no need to iterate the block in that case.

For `Environ.Map`, validation of keys has been split into two categories: 'put' and 'fetch', each of which are tailored to the constraints that the implementation actually relies upon. Specifically:
- Hashing (fetching) requires the keys to be valid WTF-8 on Windows, but does not rely on any other properties of the keys (attempting to fetch `F\x00=` is not a problem, it just won't be found)
- `create{Posix,Windows}Block` relies on the Map to always have fully valid keys (no NUL, no `=` in an invalid location, no zero-length keys), which means that the 'put' APIs need to validate that incoming keys adhere to those properties.
The relevant assertions are now documented on each of the Map functions.

Also reinstates some test cases in the `env_vars` standalone test. Some of the reinstated tests are effectively just testing the Environ.Map implementation due to how `Environ.contains`, `Environ.getAlloc`, etc are implemented, but that is not inherent to those functions so the tests are still potentially relevant if e.g. `contains` is implemented in terms of `getPosix`/`getWindows` in the future (which is totally possible and maybe a good idea since constructing the whole map is not necessary for looking up one key).

```

## Parents

- [fa3228ae42d3bc92ad66fe91e108511583129ffd](https://git.cafe/gitcafe/zig/commit/fa3228ae42d3bc92ad66fe91e108511583129ffd?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/bcb5218a2b2bce189831e68b3396cfd6f246caa2?format=markdown)
