Fix .env parsing of CRLF multi-line values#10686
Conversation
The CRLF-to-LF normalization in functions env parsing used a regex without the global flag, so only the first carriage return in a file was converted. On Windows-authored .env files this left literal \r characters inside multi-line double-quoted values, corrupting the deployed environment variable. Add the global flag and cover it with tests.
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where Windows (CRLF) line endings were not fully normalized when parsing .env files, causing carriage returns to leak into multi-line double-quoted values. This was resolved by updating the regular expression replacement in src/functions/env.ts to use the global flag (/g). Corresponding unit tests were added to src/functions/env.spec.ts to verify the fix, and the CHANGELOG.md was updated. There are no review comments, and I have no additional feedback to provide.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10686 +/- ##
=======================================
Coverage ? 57.76%
=======================================
Files ? 608
Lines ? 39158
Branches ? 7846
=======================================
Hits ? 22619
Misses ? 14730
Partials ? 1809 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
When I deploy functions from a Windows-authored
.envfile, multi-line double-quoted values come out with stray carriage returns embedded in them.The cause is in
src/functions/env.ts. The CRLF-to-LF normalization at the top ofparse()uses a regex without the global flag:So only the first CRLF in the whole file gets converted; every later line keeps its
\r. For single-line values the leftover\ris absorbed by the existing whitespace trimming, so it goes unnoticed — but inside a multi-line double-quoted value (e.g. a PEM key, exactly the case the docstring documents) the\ris preserved literally and ends up in the deployed environment variable.Fix is one character: add the
gflag so all line endings are normalized.Added two
parsetest cases (a plain CRLF file and a multi-line quoted CRLF value); the multi-line one fails before the change and passes after. Fullsrc/functionssuite is green, plustscand eslint.