theskumar / python-dotenv

Reads key-value pairs from a .env file and can set them as environment variables. It helps in developing applications following the 12-factor principles.
https://saurabh-kumar.com/python-dotenv/
BSD 3-Clause "New" or "Revised" License
7.7k stars 431 forks source link

load_dotenv() does not load multiline variables correctly #532

Open francescoVaglienti opened 3 months ago

francescoVaglienti commented 3 months ago

Given a .env such as

TEST="This is missing
no values"

and the following code

import os

from dotenv import dotenv_values, load_dotenv

load_dotenv()
config = dotenv_values()

print("--------------------")
print(config["TEST"])
print("--------------------")
print(os.environ["TEST"])
print("--------------------")

print(os.environ["TEST"] == config["TEST"])

returns

--------------------
This is missing
no values
--------------------
"This is missing
--------------------
False

This is on python-dotenv 1.0.1 using Python 3.10.14

Expected output would be

--------------------
This is missing
no values
--------------------
This is missing
no values
--------------------
True
alph486 commented 1 month ago

Have reproduced this using 1.0.1 and python 3.12.