[eas-cli] Quote env:pull values containing # or whitespace#3911
Open
ryanda9910 wants to merge 1 commit into
Open
[eas-cli] Quote env:pull values containing # or whitespace#3911ryanda9910 wants to merge 1 commit into
ryanda9910 wants to merge 1 commit into
Conversation
dotenv treats an unquoted # as the start of an inline comment and trims surrounding whitespace, so eas env:pull would write values like a #ffffff hex color or a URL with a fragment in a way that gets silently truncated when the .env file is read back. Serialize values through a helper that quotes them when needed, preferring single quotes (literal in dotenv) and falling back to double quotes with \n/\r escaping for values containing a single quote or newline. Fixes expo#2813
|
Subscribed to pull request
Generated by CodeMention Warning: The preamble and epilogue options in commentConfiguration are deprecated. Use template instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fixes #2813.
eas env:pullwrites the generated.envfile by interpolating each value directly:${name}=${value}. When a value contains a#(a hex color like#ffffff, or a URL with a fragment), dotenv reads the#as the start of an inline comment and drops everything after it, so the variable loads with a truncated or empty value. The same happens for values with surrounding whitespace (trimmed) or newlines (split across lines). The dotenv docs call this out and recommend wrapping such values in quotes: https://github.com/motdotla/dotenv#commentsRepro:
How
Added a small
serializeDotenvValuehelper inpull.tsand routed the three places that write a value through it (plain values, reused local secret values, and generated file paths).The helper quotes only when needed and is built to round-trip through the dotenv version this package ships (
16.3.1), whose parser un-escapes\n/\rinside double quotes but does not un-escape\"or\\:#, whitespace, backslashes and double quotes as-is (this also avoids accidentaldotenv-expand$interpolation),\n/\rescaping) are used only when the value contains a single quote or a newline.The one case dotenv 16.3.1 genuinely cannot represent is a value containing both a single and a double quote; that is a limitation of the bundled parser, not of the encoding.
Test Plan
Added to
EnvPull.test.ts:#-containing value is quoted in the written file and that the file round-trips back to the original value viadotenv.parse,serializeDotenvValuetest that round-trips a table of tricky values (#ffffff, URL with fragment, spaces, embedded#, single quote, newline, Windows path, leading/trailing whitespace, empty string) through the real dotenv parser, and confirms plain values stay unquoted.This is a draft pending maintainer review.