nodejs / nodejs/node

--env-file does not support inner quotes (does not behave like dotenv)

オープン
#54,134 コメント 20 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

confirmed-bug dotenv
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v20.16.0

Platform
Darwin <redacted> 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64
Subsystem

No response

What steps will reproduce the bug?

inspired by this comment: https://github.com/nodejs/node/pull/50814#issuecomment-1817949911

  1. create an .env file:

    INNER_QUOTES="1: foo'bar"baz`qux"
    INNER_QUOTES_WITH_NEWLINE="2: foo bar\ni am "on" newline, 'yo'"
    
  2. test with dotenv:

    // envtest-dotenv.js
    require("dotenv").config();
    console.log(process.env.INNER_QUOTES);
    console.log(process.env.INNER_QUOTES_WITH_NEWLINE);
    

    $ node envtest-dotenv.js

  3. test with --env-file

    // envtest.js
    console.log(process.envconsole.log(process.env.INNER_QUOTES);
    console.log(process.env.INNER_QUOTES_WITH_NEWLINE);
    

    $ node --env-file=.env envtest.js

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

outputs should be the same.

// dotenv output:

1: foo'bar"baz`qux
2: foo bar
i am "on" newline, 'yo'
What do you see instead?

output are different, node native terminates at the first occurrence of the double quote:

// --env-file output
1: foo'bar
2: foo bar
i am

compare that to dotenv:

1: foo'bar"baz`qux
2: foo bar
i am "on" newline, 'yo'
Additional information
  • this makes it impossible to have env-variables that contain all three quotes (", ' and `) and newlines.
  • There is no alternative to inner quotes, because escaping quotes have been rejected https://github.com/nodejs/node/pull/50814
  • It's very problematic in many cases since depending on the quotes you are using, you need to use different outer quotes
  • i noticed that because i am writing some tooling that creates those .env files based on some other configuration. I just used double quotes as outer quotes and noticed that it fails when the string contains double quotes
  • be aware that dotenv also has a bug, when your string contains an actual newline (not "\n") AND has inner quotes, it will cut the string off at the line break. It works if the string does not contain inner quotes. It also works if you instead use "\n" instead of an actual line break. The output will still be the same and will have a real line break in it (as long as you put outer quotes around the string. without quotes, the \n will be literally in the output as "\n")

And

  • since the format is so problematic, maybe its time for a better format?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、node --env-file=.env envtest.js を使って .env の例を再現し、出力を dotenv と比較します。--env-file のパースのエントリポイントと既存のテストを追跡し、その後、ネイティブパーサーが期待される出力と一貫して内部の引用符と改行を保持するようにし、これらのケースのカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, nodejs
領域
cli
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。