fix(builder): strip UTF-8 BOM from .ino sources before preprocessing #2983
+11
−0
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
.ino
is 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
.cpp
and any copied sources are clean.Refs: arduino/arduino-ide#2752
Please check if the PR fulfills these requirements
See how to contribute
UPGRADING.md
has been updated with a migration guide (for breaking changes)configuration.schema.json
updated 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
.ino
and additional files.What is the current behavior?
.ino
is 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?
.ino
files.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