Repository navigation
fix: recognize includes in UTF-8 BOM-prefixed source files - #484
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
buurosaaqi-dev
left a comment
There was a problem hiding this comment.
PR Review: #484 — fix: recognize includes in UTF-8 BOM-prefixed source files
Summary: LGTM / Approved.
A concise, elegant fix for issue #158. Switching the file read encoding from utf8 to Python's built-in utf-8-sig transparently strips the leading \xef\xbb\xbf BOM signature if present, while behaving identically to standard utf-8 on files without a BOM.
Verification
- Test Coverage: Verified the parametrized tests in
cpplint_clitest.py(test_utf8_bom_before_first_includeandtest_utf8_bom_still_reports_missing_own_header) accurately confirm that:- An own-header
#include "sample.h"preceded by a BOM is recognized and does not produce a false-positivebuild/includeviolation. - Legitimate missing own-header violations continue to be flagged when an unrelated header is included, whether a BOM is present or not.
- An own-header
- CI Status: Verified all 6 GitHub Actions test jobs (Ubuntu, macOS, Windows across Python 3.10 and 3.x) and
pre-commit.ciare green (SUCCESS). - Changelog:
CHANGELOG.rstcorrectly records the fix referencing #158.
Note for completeness (Non-blocking)
When filename == "-" (reading from sys.stdin), sys.stdin.read() uses the platform stream encoding rather than utf-8-sig. If piped inputs with a BOM ever become a concern, a minor startswith("\ufeff") strip on the stdin buffer could be added in a follow-up. For file-based usage, this PR completely and cleanly resolves the issue.
Ready to merge.
Fixes #158.
Problem
UTF-8 BOM is retained as U+FEFF when source files are read using
encoding="utf8". This can hide a first-line#includedirective and cause a falsebuild/includewarning.Changes
utf-8-sigfor source-file decoding.Verification
AI assistance was used for analysis, implementation and testing.