Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- ...
### Fixed

- Strip a leading UTF-8 BOM from `.env` file contents so the first variable is no longer silently lost when the file is saved with BOM (e.g. by some JetBrains IDEs on Windows) by [@h1whelan] in [#640]

## [1.2.2] - 2026-03-01

Expand Down Expand Up @@ -432,6 +434,7 @@ os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).
[#563]: https://github.com/theskumar/python-dotenv/pull/563
[#497]: https://github.com/theskumar/python-dotenv/pull/497
[#161]: https://github.com/theskumar/python-dotenv/issues/161
[#640]: https://github.com/theskumar/python-dotenv/pull/640
[790c5c0]: https://github.com/theskumar/python-dotenv/commit/790c5c02991100aa1bf41ee5330aca75edc51311

<!-- contributors -->
Expand Down Expand Up @@ -460,6 +463,7 @@ os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).
[@gergelyk]: https://github.com/gergelyk
[@gongqingkui]: https://github.com/gongqingkui
[@greyli]: https://github.com/greyli
[@h1whelan]: https://github.com/h1whelan
[@harveer07]: https://github.com/harveer07
[@jadutter]: https://github.com/jadutter
[@jankislinger]: https://github.com/jankislinger
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Error(Exception):

class Reader:
def __init__(self, stream: IO[str]) -> None:
self.string = stream.read()
self.string = stream.read().removeprefix("\ufeff")
self.position = Position.start()
self.mark = Position.start()

Expand Down
29 changes: 29 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,35 @@
),
],
),
# UTF-8 BOM at the start of the file should be stripped
(
"\ufeffa=b",
[
Binding(
key="a",
value="b",
original=Original(string="a=b", line=1),
error=False,
)
],
),
(
"\ufeffa=b\nc=d",
[
Binding(
key="a",
value="b",
original=Original(string="a=b\n", line=1),
error=False,
),
Binding(
key="c",
value="d",
original=Original(string="c=d", line=2),
error=False,
),
],
),
],
)
def test_parse_stream(test_input, expected):
Expand Down