Open tertsdiepraam opened 1 year ago
Most dotenv parsers seem to have the following features:
#
marks a comment unless it's quoted or escapedAs far as I can tell, there's not really a spec. Everyone just goes with "it's bash-like".
Examples:
FWIW, Systemd has this description for how EnvironmentFile
is interpreted:
The text file should contain newline-separated variable assignments. Empty lines, lines without an "=" separator, or
lines starting with ";" or "#" will be ignored, which may be used for commenting. The file must be UTF-8 encoded. Valid characters are unicode scalar values[7] other than noncharacters[8], U+0000
NUL, and U+FEFF byte order mark[9]. Control codes other than NUL are allowed.
In the file, an unquoted value after the "=" is parsed with the same backslash-escape rules as unquoted text[10] in a POSIX shell, but unlike in a shell, interior whitespace is preserved and
quotes after the first non-whitespace character are preserved. Leading and trailing whitespace (space, tab, carriage return) is discarded, but interior whitespace within the line is preserved
verbatim. A line ending with a backslash will be continued to the following one, with the newline itself discarded. A backslash "\" followed by any character other than newline will preserve the
following character, so that "\\" will become the value "\".
In the file, a "'"-quoted value after the "=" can span multiple lines and contain any character verbatim other than single quote, like single-quoted text[11] in a POSIX shell. No backslash-escape
sequences are recognized. Leading and trailing whitespace outside of the single quotes is discarded.
In the file, a """-quoted value after the "=" can span multiple lines, and the same escape sequences are recognized as in double-quoted text[12] of a POSIX shell. Backslash ("\") followed by any
of ""\`$" will preserve that character. A backslash followed by newline is a line continuation, and the newline itself is discarded. A backslash followed by any other character is ignored; both
the backslash and the following character are preserved verbatim. Leading and trailing whitespace outside of the double quotes is discarded
We currently use
rust-ini
to parse.env
files forenv
's-f
/--file
flag. We could move to a dedicated.env
parser. There are some libraries for this available on crates.io, but we'll have to evaluate them.