fix: strip UTF-8 BOM from funcignore and fix negation pattern handling#7311
fix: strip UTF-8 BOM from funcignore and fix negation pattern handling#7311
Conversation
The go-gitignore library does not handle UTF-8 BOM (byte order mark) that some Windows editors (e.g. Notepad) prepend to files. When a .funcignore file has a BOM, the invisible prefix bytes become part of the first pattern, causing it to never match. This broke the node_modules exclusion detection in resolveFunctionAppRemoteBuild, leading to incorrect remoteBuild validation results. Changes: - Strip UTF-8 BOM from .funcignore content before parsing in both resolveFunctionAppRemoteBuild (validation) and createDeployableZip (packaging) for consistent behavior - Switch createDeployableZip from gitignore.NewFromFile to manual read + gitignore.New for consistency with validation code path - Fix negation pattern handling in createDeployableZip: check match.Ignore() instead of just match != nil, so negation patterns (e.g. !node_modules/important) correctly include files - Add comprehensive BOM-handling tests and stripUTF8BOM unit tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes .funcignore parsing and zip-packaging behavior for Azure Functions by normalizing ignore-file reading (including UTF-8 BOM stripping) and correctly honoring negation patterns, then adds extensive tests around remoteBuild resolution.
Changes:
- Add
stripUTF8BOMhelper and apply it when reading ignore-file contents before feedinggo-gitignore. - Make zip packaging (
createDeployableZip) parse ignore rules from in-memory contents (avoids open handle) and respect negation patterns viamatch.Ignore(). - Expand
resolveFunctionAppRemoteBuildtest coverage for BOM handling, customer scenario matrix, edge cases, and TypeScript parity.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cli/azd/pkg/project/service_target_functionapp_test.go | Adds broad test coverage for BOM handling and remoteBuild / .funcignore scenario combinations. |
| cli/azd/pkg/project/service_target_functionapp.go | Strips UTF-8 BOM from .funcignore contents prior to gitignore parsing in remoteBuild validation logic. |
| cli/azd/pkg/project/project_utils.go | Aligns ignore parsing to os.ReadFile + BOM stripping + gitignore.New, and fixes negation handling in zip packaging. |
Close and remove the temporary zip file when reading the ignore file fails with a non-NotExist error, preventing file handle leaks and orphaned temp files (especially on Windows). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b708211 to
f6fd3b6
Compare
weikanglim
left a comment
There was a problem hiding this comment.
Looks good! Thanks for fixing the Windows UTF-8 bom issue and the existing match pattern.
Left a minor comment on test duplication.
The previous Windows BuildCLI failure was a known file-locking flake in Test_CLI_Extension_ForceInstall — unrelated to this PR's changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses review feedback from @weikanglim. The CustomerScenarios test was duplicating 8 of 9 cases from JavaScriptMatrix. Merged Case 9 (true + no funcignore) into JavaScriptMatrix and added customer case comments for traceability. Removed the duplicate test function. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
|
Do not merge. Waiting for user to confirm. |
Summary
Fixes
.funcignoreparsing failures caused by UTF-8 BOM (Byte Order Mark) and corrects negation pattern handling in the zip packaging path. Adds comprehensive test coverage for allremoteBuild×.funcignorecombinations.Problem
A customer reported unexpected behavior when using
.funcignorewithremoteBuildsettings on azd 1.23.12. Investigation revealed three bugs:UTF-8 BOM breaks pattern matching: The
go-gitignorelibrary does not strip BOM (\xef\xbb\xbf) from file contents. Windows editors (e.g., Notepad pre-Win11) often add BOM to UTF-8 files, causing the first pattern (typicallynode_modules) to become\xef\xbb\xbfnode_modules— which never matches.Inconsistent parsing between validation and packaging: The validation path (
resolveFunctionAppRemoteBuild) usedgitignore.New()withbytes.NewReader(), while the packaging path (createDeployableZip) usedgitignore.NewFromFile(). The latter holds an open file handle (problematic on Windows temp dirs) and doesn't strip BOM.Negation patterns treated as exclusions: In the packaging path, code checked
if match != nilwithout checkingmatch.Ignore(), so negation patterns like!important_modulewere incorrectly treated as exclusions.Fix
stripUTF8BOM()helper function that removes BOM prefix if presentos.ReadFile()→stripUTF8BOM()→gitignore.New()for consistent behaviormatch != nil && match.Ignore()in the packaging pathTest Coverage (46 total: 8 existing + 38 new)
BOMHandlingStripUTF8BOMCustomerScenariosEdgeCasesTypeScriptParityCustomer Scenario Matrix
Verification
mage preflightpasses (gofmt, go fix, copyright, lint 0 issues, cspell 0 issues, build, all tests)