Skip to main content

parse_env

Function parse_env 

Source
pub fn parse_env(text: &str) -> Vec<ExtractedPair>
Expand description

Parse KEY=VALUE lines from an .env file.

Quoting styles recognised:

  • KEY="value" and KEY='value' (matching ASCII single/double quotes).
  • KEY=`value` backtick-quoted bodies (some shells + dotenv-cli accept these).
  • Bare KEY=value with no quotes.

Inline comments are stripped on UNQUOTED values only. Sample seen in .env files: DB_PASS=p4ssw0rd # rotate quarterly -> value = p4ssw0rd. Quoted values keep # because the user has explicitly opted into the literal string including the hash.