theskumar / theskumar/python-dotenv

Multi-line variables not loading correctly with load_env

Offen
#555 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.9k
Forks
581
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

When reading a multi-line environment variable (e.g. an SSH key) only the first line is read when using load_env. dotenv_values appears to read the multiline variable correctly.

Tested on a Apple M2 MacBook Air running Sonoma 14.7.4 with Python 3.12.9. While I had this issue inside a functions-framework function, I was able to reproduce it outside of that environment (see below.)

As an example, try the following .env file:

FOO="foo"
BAR="bar"
BAZ1="baz
baz
baz
baz
baz
"
BAZ2="baz\nbaz\nbaz"
LAST="last"

And the following Python code:

from dotenv import load_dotenv, dotenv_values
import os

load_dotenv()
print(os.environ.get('FOO'))
print(os.environ.get('BAR'))

print(os.environ.get('BAZ1'))
print(len(os.environ.get('BAZ1')))

print(os.environ.get('BAZ2'))
print(len(os.environ.get('BAZ2')))

print(os.environ.get('LAST'))

env = dotenv_values()
print(env)

print(env.get('BAZ1'))
print(len(env.get('BAZ1')))

print(env.get('BAZ2'))
print(len(env.get('BAZ2')))

When I run that code, it produces the following output:

foo
bar
"baz
4
baz
3
last
OrderedDict({'FOO': 'foo', 'BAR': 'bar', 'BAZ1': 'baz\nbaz\nbaz\nbaz\nbaz\n', 'BAZ2': 'baz\nbaz\nbaz', 'LAST': 'last'})
baz
baz
baz
baz
baz

20
baz
baz
baz
11

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduce the issue with the shown .env file and Python snippet, then trace the load_env/load_dotenv path and compare it with dotenv_values. Done means quoted multiline variables such as BAZ1 are fully loaded into the environment while the existing escaped-newline behavior remains correct.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devops
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.