Skip to content

First environment variable in a .env file is silently ignored on a file with BOM (Byte Order Mark) format #637

@angel-masterdoc

Description

@angel-masterdoc

When executing load_dotenv() with a .env file saved in a BOM (Byte Order Mark) aware format, the first environment variable is silently ignored, but the rest are added.

I assume this occurs since an invisible character is added at the beginning of the .env file, and that line is ignored. This can be problematic since it is an invisible character, a silent error, and also JetBrains IDEs like to set BOM by default when opening .env files (at least in Windows environments)

Steps to reproduce:

  • Use any version of python-dotenv from 1.0.1 to 1.2.2
  • Create a .env file with BOM
  • Add several variables
  • load_dotenv
    => All variables are loaded but the first one.
    My expected behaviour: explicit fail or load of all environment variables.
Image

Thanks a lot in advance to the reader, answerer, and anyone who contributes to this repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions