Skip to content

Replace DotNet.Glob with Microsoft.Extensions.FileSystemGlobbing#1767

Merged
grvillic merged 2 commits intomainfrom
jamieMagee/replace-dotnet-glob-with-filesystemglobbing
Apr 7, 2026
Merged

Replace DotNet.Glob with Microsoft.Extensions.FileSystemGlobbing#1767
grvillic merged 2 commits intomainfrom
jamieMagee/replace-dotnet-glob-with-filesystemglobbing

Conversation

@JamieMagee
Copy link
Copy Markdown
Member

Fixes #201

What

Swaps DotNet.Glob for Microsoft.Extensions.FileSystemGlobbing in all three call sites:

  • DetectorProcessingService (directory exclusion via --DirectoryExclusionList)
  • YarnLockComponentDetector (workspace pattern matching)
  • RustSbomDetector (Cargo workspace include/exclude rules)

Why

DotNet.Glob v2.1.1 throws IndexOutOfRangeException on ** patterns like **/samples/**. This has been broken since 2022. PR #1091 tried to fix it by hand-porting npm's minimatch (862 lines of C#) but that landed on a dead branch and never made it to main.

FileSystemGlobbing is a first-party Microsoft package. No custom code to maintain.

Notable behavior difference

FileSystemGlobbing's ** does not match zero trailing path segments. So **/node_modules/** won't match the path project/node_modules by itself -- only project/node_modules/something.

The directory exclusion predicate works around this by adding a companion pattern: when it sees **/dir/**, it also adds **/dir. The other two call sites (Yarn workspaces, Rust Cargo) don't use trailing ** patterns, so they're unaffected.

All paths are normalized to forward slashes before matching, which removes the old DotNet.Glob-specific backslash escaping (Replace("\\", "[\\]")).

Fixes #201. DotNet.Glob v2.1.1 throws IndexOutOfRangeException on **
patterns (e.g. **/samples/**). Replace it with
Microsoft.Extensions.FileSystemGlobbing in all three call sites:

- DetectorProcessingService: directory exclusion via --DirectoryExclusionList
- YarnLockComponentDetector: workspace pattern matching
- RustSbomDetector: Cargo workspace include/exclude rules

FileSystemGlobbing's ** does not match zero trailing segments, so
**/dir/** patterns get a companion **/dir pattern added in the
directory exclusion predicate.

Paths are normalized to forward slashes before matching, which replaces
the DotNet.Glob-specific backslash escaping workaround.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This comment was marked as outdated.

- Respect allowWindowsPaths flag: skip patterns containing backslashes
  when the flag is false, restoring the original behavior where
  backslash-based patterns don't match on non-Windows platforms
- Remove unused rootPath variable in YarnLockComponentDetector
- Fix stale XML doc on AddGlobRule (was claiming OS-dependent case
  sensitivity, but the code always uses OrdinalIgnoreCase)
- Add test for trailing ** companion pattern workaround
- Fix absolute path handling in directory exclusion predicate by
  stripping the root prefix before matching

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces DotNet.Glob with Microsoft.Extensions.FileSystemGlobbing across the orchestrator’s directory exclusion logic and two detectors (Yarn + Rust) to avoid known DotNet.Glob failures on ** patterns and reduce custom maintenance burden.

Changes:

  • Swapped globbing implementation to Microsoft.Extensions.FileSystemGlobbing.Matcher for directory exclusions, Yarn workspace matching, and Rust Cargo workspace include/exclude rules.
  • Added a unit test covering the **/dir/** compatibility workaround (ensuring the directory itself is excluded, not just descendants).
  • Updated package references to remove DotNet.Glob and pin Microsoft.Extensions.FileSystemGlobbing centrally.
Show a summary per file
File Description
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs Adds coverage for the trailing-/** workaround to exclude the directory itself.
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs Reimplements directory exclusion predicate using Matcher, with path normalization + trailing-/** companion pattern handling.
src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj Replaces DotNet.Glob package reference with Microsoft.Extensions.FileSystemGlobbing.
src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.cs Switches workspace file matching from Glob to Matcher over normalized relative paths.
src/Microsoft.ComponentDetection.Detectors/rust/RustSbomDetector.cs Switches Cargo workspace include/exclude matching from Glob lists to Matcher.
src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj Replaces DotNet.Glob package reference with Microsoft.Extensions.FileSystemGlobbing.
Directory.Packages.props Removes DotNet.Glob version pin; adds Microsoft.Extensions.FileSystemGlobbing v8.0.0.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new

@grvillic grvillic merged commit e05ea39 into main Apr 7, 2026
30 checks passed
@grvillic grvillic deleted the jamieMagee/replace-dotnet-glob-with-filesystemglobbing branch April 7, 2026 16:55
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.0%. Comparing base (97f3d73) to head (63c8f5e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #1767   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate our use of ** with Dotnet.Glob

4 participants