Skip to content

Conversation

@svix-jbrown
Copy link

@svix-jbrown svix-jbrown commented Jan 30, 2026

This loosens the key parser to allow all POSIX-legal and reasonable names (basically, ignoring the things that don't make sense in a text file like BEL, and ignoring leading digits as recommended by POSIX).

Note

Some more background here for anyone reading who doesn't know; there's a lot of nonsense on the Internet, like this very-popular Stack Overflow thread that conflates environment variables with shell variables and other concepts. Environment variables are very loosey-goosy -- they're just an array of strings, which by convention should contain at least one =! POSIX 2024-8.1 specifies that an environment variable name may be any character other than NUL or =. This is actually pretty common (for example, most Windows environment variable names have % in them, and many enterprise-y Unix applications use environment variables containing the : character). Shells (like bash) have a notion of shell variables, which are more restrictive than environment variables; for example, bash's are limited to [a-zA-Z_][a-zA-Z0-9_]*. Many shells provide a way to convert a shell variable to an environment variable, like bash's export word. However, even in a shell you can set arbitrary environment variables by using the syntax env 0scary=whatever ./my-program.

This PR is a superset of what's described in #158.

Unfortunately, this does somewhat conflict with #138, in that some of the bourne shell substitution metacharacters are also legal environment variable name characters. I personally would get more value out of supporting all legal environment variable names than I would out of supporting bash-style ${foo:-default_if_unset} substitutions, but I can see both arguments.

@svix-jbrown svix-jbrown force-pushed the jbrown/parse-all-legal-names branch from 6335066 to 505443e Compare January 30, 2026 22:03
@svix-jbrown svix-jbrown marked this pull request as ready for review January 30, 2026 22:05
@svix-jbrown svix-jbrown changed the title allow parsing all legal environment variable names allow parsing more legal environment variable names Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant