From a7968ad69369263e57e90cb9f20353264d62d3f2 Mon Sep 17 00:00:00 2001 From: xav-ie Date: Sat, 25 Jan 2025 18:26:39 -0500 Subject: [PATCH] fix(from env): replace special chars `\n`, `\r`, `\t` Many .env loaders replace `\n`, `\r`, `\t`. Follow the standard of properly replacing with their literal equivalents when loading the variable for use. --- modules/formats/from-env.nu | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/formats/from-env.nu b/modules/formats/from-env.nu index 458f2604b..09ec1e5b9 100644 --- a/modules/formats/from-env.nu +++ b/modules/formats/from-env.nu @@ -2,10 +2,15 @@ # may be used like this: open .env | load-env # works with quoted and unquoted .env files def "from env" []: string -> record { - lines + lines | split column '#' # remove comments - | get column1 + | get column1 | parse "{key}={value}" - | str trim value -c '"' # unquote values + | update value { + str trim -c '"' | # unquote values + str replace -a "\\n" "\n" # replace `\n` with newline char + str replace -a "\\r" "\r" # replace `\r` with carriage return + str replace -a "\\t" "\t" # replace `\t` with tab + } | transpose -r -d }