From c3c0a3ee5cac4a77f038cd9490fe32909c3887f0 Mon Sep 17 00:00:00 2001 From: IlyasShabi <33763729+IlyasShabi@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:09:13 +0100 Subject: [PATCH] src: support multi-line values for .env file PR-URL: https://github.com/nodejs/node/pull/51289 Reviewed-By: Yagiz Nizipli Reviewed-By: Zeyu "Alex" Yang Reviewed-By: Rafael Gonzaga Reviewed-By: Franziska Hinkelmann --- doc/api/cli.md | 18 ++++++ src/node_dotenv.cc | 97 +++++++++++++++------------------ src/node_dotenv.h | 2 +- test/fixtures/dotenv/valid.env | 25 +++++++++ test/parallel/test-dotenv.js | 14 +++++ test/parallel/util-parse-env.js | 14 ++++- 6 files changed, 114 insertions(+), 56 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 9d8d23a78ea734..f65a9f60a2e669 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -655,6 +655,10 @@ of `--enable-source-maps`. Loads environment variables from a file relative to the current directory, @@ -691,6 +695,20 @@ They are omitted from the values. USERNAME="nodejs" # will result in `nodejs` as the value. ``` +Multi-line values are supported: + +```text +MULTI_LINE="THIS IS +A MULTILINE" +# will result in `THIS IS\nA MULTILINE` as the value. +``` + +Export keyword before a key is ignored: + +```text +export USERNAME="nodejs" # will result in `nodejs` as the value. +``` + ### `-e`, `--eval "script"`