fix(builder): strip UTF-8 BOM from .ino sources before preprocessing#2983
Merged
Conversation
When a sketch .ino is saved as UTF-8 *with BOM*, the BOM bytes (EF BB BF) reach the compiler and cause: stray '\357' in program stray '\273' in program stray '\277' in program This strips the BOM at read-time so the merged .cpp and copied sources are clean. Refs: arduino/arduino-ide#2752
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2983 +/- ##
=======================================
Coverage 68.35% 68.36%
=======================================
Files 241 241
Lines 22724 22731 +7
=======================================
+ Hits 15534 15541 +7
Misses 5992 5992
Partials 1198 1198
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Hi @per1234 |
cmaglie
approved these changes
Sep 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arduino CLI: Strip UTF‑8 BOM from .ino before preprocessing
Summary
When a sketch
.inois saved as UTF-8 with BOM, the three BOM bytes (EF BB BF) reach the compiler and cause:This PR strips the BOM at read-time so the merged
.cppand any copied sources are clean.Refs: #3015
Please check if the PR fulfills these requirements
See how to contribute
UPGRADING.mdhas been updated with a migration guide (for breaking changes)configuration.schema.jsonupdated if new parameters are added.What kind of change does this PR introduce?
Bug fix — make the CLI robust to UTF-8 BOM at the start of
.inoand additional files.What is the current behavior?
.inois saved as UTF-8 with BOM, the BOM bytes are preserved into the merged.cpp, leading to compiler errors (stray '\357' / '\273' / '\277').What is the new behavior?
.inofiles.Implementation notes
internal/arduino/builder/sketch.go→sketchMergeSources()(viagetSource(...))internal/arduino/builder/sketch.go→sketchCopyAdditionalFiles(...)Test plan (manual)
Before this patch: fails with:
After this patch: succeeds.
Control: Save as UTF-8 (no BOM) → succeeds (unchanged).
Does this PR introduce a breaking change?
No. The change only strips a BOM if present; no impact on existing UTF-8 (no BOM) files or other encodings.
Other information