allow parsing more legal environment variable names #161
+58
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thanNULor=. 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'sexportword. However, even in a shell you can set arbitrary environment variables by using the syntaxenv 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.