Skip to content

[Dotenv] Fix can not load BOM-signed env files #58216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

[Dotenv] Fix can not load BOM-signed env files #58216

wants to merge 1 commit into from

Conversation

hosni
Copy link
Contributor

@hosni hosni commented Sep 9, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58214
License MIT

In this PR, I fixed the load env file BOM characters.
You can see the full explanation of the issue: #58214
More about BOM: Byte Order Mark

@hosni
Copy link
Contributor Author

hosni commented Sep 9, 2024

Unit tests failed, but that's not my fault!
The reason is: (Testing /home/runner/work/symfony/symfony/src/Symfony/Bridge/Twig)
My unit tests working perfectly.

@@ -9,6 +10,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c

* 6.4.11 (2024-08-30)

* bug #58214 [Dotenv] Fix can not load BOM-signed env files (hosni)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert. This file is generated.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotenv files are modeled after sourced shell scripts.
I just tested and neither sh nor bash support parsing dotenv files that start with a BOM.
This means we should not do it.

Instead, we might consider throwing an exception when one is found.
I'd suggest doing it in the doLoad method.

Also, let's use str_starts_with to check for it.

@nicolas-grekas
Copy link
Member

Please submit a new PR if you want to provide the exception I suggested.

@xabbuh
Copy link
Member

xabbuh commented Sep 16, 2024

see #58274 for the exception

nicolas-grekas added a commit that referenced this pull request Sep 16, 2024
…files with BOM (xabbuh)

This PR was merged into the 5.4 branch.

Discussion
----------

[Dotenv] throw a meaningful exception when parsing dotenv files with BOM

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58214
| License       | MIT

This replaces #58216. Other than in that PR I did not account for UTF-16 and UTF-32 byte-order-mark variants as that would IMO require us to first reliably detect the file encoding.

Commits
-------

b4f3eaa throw a meaningful exception when parsing dotenv files with BOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants