From 74d946020431f5f74e8f32ffc03398c761c11a99 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 15 Dec 2021 11:11:39 -0800 Subject: [PATCH 1/5] Fixing a bug where empty variables in .env files were read as multi-line values --- src/functions/env.ts | 3 ++- src/test/functions/env.spec.ts | 41 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/functions/env.ts b/src/functions/env.ts index 4df472f0030..2e6d4edb383 100644 --- a/src/functions/env.ts +++ b/src/functions/env.ts @@ -49,7 +49,7 @@ const LINE_RE = new RegExp( "(" + // begin optional value "\\s*'(?:\\\\'|[^'])*'|" + // single quoted or '\\s*"(?:\\\\"|[^"])*"|' + // double quoted or - "[^#\\r\\n]+" + // unquoted + "[^#=\\r\\n]*" + // unquoted ")?" + // end optional value "\\s*" + // trailing whitespaces "(?:#[^\\n]*)?" + // optional comment @@ -109,6 +109,7 @@ export function parse(data: string): ParseResult { v = v.replace(/\\([\\'"])/g, "$1"); } } + envs[k] = v; } diff --git a/src/test/functions/env.spec.ts b/src/test/functions/env.spec.ts index ab9cca27589..04e5e73ab88 100644 --- a/src/test/functions/env.spec.ts +++ b/src/test/functions/env.spec.ts @@ -135,26 +135,33 @@ BAR=bar want: { FOO: "foo" }, }, { - description: "should ignore comments", + description: "should handle empty values", input: ` -FOO=foo # comment -# line comment 1 -# line comment 2 -BAR=bar # another comment +FOO= +BAR= "blah" `, - want: { FOO: "foo", BAR: "bar" }, - }, - { - description: "should ignore empty lines", - input: ` -FOO=foo - - -BAR=bar - -`, - want: { FOO: "foo", BAR: "bar" }, + want: { FOO: "", BAR: "blah" }, }, + // { + // description: "should ignore comments", + // input: ` + // FOO=foo # comment + // # line comment 1 + // # line comment 2 + // BAR=bar # another comment + // `, + // want: { FOO: "foo", BAR: "bar" }, + // }, + // { + // description: "should ignore empty lines", + // input: ` + // FOO=foo + + // BAR=bar + + // `, + // want: { FOO: "foo", BAR: "bar" }, + // }, ]; tests.forEach(({ description, input, want }) => { From 7a274511c95f9d85697be9b30ebce256b76097e8 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 15 Dec 2021 11:17:43 -0800 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b897142ec3b..7b637cfc2bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ - Fixes issue when installing a Firebase Extension where secrets would be created before validation. - Fixes issue with filtering on a specific storage bucket using functions in the emulator (#3893) - Fixes check in Cloud Functions for Firebase initialization to check for API enablement before trying to enable them. (#2574) -- No longer tries to clean up function build images from Artifact Registry when Artifact Registry is not enabled (#3943) +- No longer tries to clean up function build images from Artifact Registry when Artifact Registry is not enabled. (#3943) +- Fixes issue where empty variables in .env files would instead read as multi-line values. (#3934) From 4da74de50740203205ca1fb4ccf3f12097b047d9 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 15 Dec 2021 12:22:55 -0800 Subject: [PATCH 3/5] take 2 --- src/functions/env.ts | 4 ++-- src/test/functions/env.spec.ts | 40 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/functions/env.ts b/src/functions/env.ts index 2e6d4edb383..644cd24be8f 100644 --- a/src/functions/env.ts +++ b/src/functions/env.ts @@ -45,11 +45,11 @@ const LINE_RE = new RegExp( "^" + // begin line "\\s*" + // leading whitespaces "(\\w+)" + // key - "\\s*=\\s*" + // separator (=) + "\\s*=[\\f\\t\\v]*" + // separator (=) "(" + // begin optional value "\\s*'(?:\\\\'|[^'])*'|" + // single quoted or '\\s*"(?:\\\\"|[^"])*"|' + // double quoted or - "[^#=\\r\\n]*" + // unquoted + "[^#\\r\\n]*" + // unquoted ")?" + // end optional value "\\s*" + // trailing whitespaces "(?:#[^\\n]*)?" + // optional comment diff --git a/src/test/functions/env.spec.ts b/src/test/functions/env.spec.ts index 04e5e73ab88..efc5e470fab 100644 --- a/src/test/functions/env.spec.ts +++ b/src/test/functions/env.spec.ts @@ -142,26 +142,26 @@ BAR= "blah" `, want: { FOO: "", BAR: "blah" }, }, - // { - // description: "should ignore comments", - // input: ` - // FOO=foo # comment - // # line comment 1 - // # line comment 2 - // BAR=bar # another comment - // `, - // want: { FOO: "foo", BAR: "bar" }, - // }, - // { - // description: "should ignore empty lines", - // input: ` - // FOO=foo - - // BAR=bar - - // `, - // want: { FOO: "foo", BAR: "bar" }, - // }, + { + description: "should ignore comments", + input: ` + FOO=foo # comment + # line comment 1 + # line comment 2 + BAR=bar # another comment + `, + want: { FOO: "foo", BAR: "bar" }, + }, + { + description: "should ignore empty lines", + input: ` + FOO=foo + + BAR=bar + + `, + want: { FOO: "foo", BAR: "bar" }, + }, ]; tests.forEach(({ description, input, want }) => { From 13a7c8d883f46bece51d63b366ccd23dd711dcbe Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 15 Dec 2021 12:55:38 -0800 Subject: [PATCH 4/5] formats --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5e2841cdb..37a132912f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,3 @@ - Show error message when running `firebase init hosting:github` with no Hosting config in `firebase.json`. (#3113) - Fixes issue where `remoteconfig:get` was not fetching the latest version by default. (#3559) - Fixes issue where empty variables in .env files would instead read as multi-line values. (#3934) - From bafc3d8be3e253ad9e574e1f1096693092c42a35 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 15 Dec 2021 13:21:03 -0800 Subject: [PATCH 5/5] adding another test case --- src/test/functions/env.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/functions/env.spec.ts b/src/test/functions/env.spec.ts index efc5e470fab..8679bfee782 100644 --- a/src/test/functions/env.spec.ts +++ b/src/test/functions/env.spec.ts @@ -142,6 +142,14 @@ BAR= "blah" `, want: { FOO: "", BAR: "blah" }, }, + { + description: "should handle quoted values after a newline", + input: ` +FOO= +"blah" +`, + want: { FOO: "blah" }, + }, { description: "should ignore comments", input: `