Skip to content

Fix .env parsing of CRLF multi-line values#10686

Open
sarathfrancis90 wants to merge 1 commit into
firebase:mainfrom
sarathfrancis90:fix-env-crlf-multiline
Open

Fix .env parsing of CRLF multi-line values#10686
sarathfrancis90 wants to merge 1 commit into
firebase:mainfrom
sarathfrancis90:fix-env-crlf-multiline

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

When I deploy functions from a Windows-authored .env file, 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 of parse() uses a regex without the global flag:

data = data.replace(/\r\n?/, "\n"); // For Windows support.

So only the first CRLF in the whole file gets converted; every later line keeps its \r. For single-line values the leftover \r is 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 \r is preserved literally and ends up in the deployed environment variable.

Fix is one character: add the g flag so all line endings are normalized.

Added two parse test cases (a plain CRLF file and a multi-line quoted CRLF value); the multi-line one fails before the change and passes after. Full src/functions suite is green, plus tsc and eslint.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@c056411). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants