FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the file

Đang mở Phù hợp với người mới
#136,989 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@makazeu đang làm issue này rồi.

Từ ngày 5/11/2026.

  • #137020 của @makazeu — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs, đặc biệt là mã EnumerateFileSystemInfos được liên kết trong issue. Tái hiện lỗi bằng ứng dụng dựa trên tệp được cung cấp, trong đó rootDir và file là cùng một đường dẫn, sau đó kiểm tra các bài kiểm thử FileSystemGlobbing liên quan. Hoàn tất khi Match() trả về HasMatches == false mà không ném ngoại lệ trong trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area-Extensions-FileSystem
Description

See title and file-based app repro below.

Reproduction Steps
#:package [email protected]

using Microsoft.Extensions.FileSystemGlobbing;

var root = Path.GetPathRoot(Environment.CurrentDirectory)!;
var matcher = new Matcher();
matcher.AddInclude("MyFile.txt");

Console.WriteLine($"Match(rootDir: \"{root}\", file: \"{root}\")");
Console.WriteLine(matcher.Match(root, root).HasMatches);
Expected behavior

Match() returns a result with HasMatches == false and doesn't throw an exception.

I'm unsure whether it would/should be possible to setup a matcher which would match the path root.

Actual behavior

Match throws an exception:

Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'startIndex')
   at System.String.IndexOfAny(Char[] anyOf, Int32 startIndex, Int32 count)
   at Microsoft.Extensions.FileSystemGlobbing.InMemoryDirectoryInfo.EnumerateFileSystemInfos()+MoveNext()
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Match(DirectoryInfoBase directory, String parentRelativePath)
   at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Execute()
   at Microsoft.Extensions.FileSystemGlobbing.Matcher.Execute(DirectoryInfoBase directoryInfo)
   at Microsoft.Extensions.FileSystemGlobbing.MatcherExtensions.Match(Matcher matcher, String rootDir, IEnumerable`1 files)
   at Microsoft.Extensions.FileSystemGlobbing.MatcherExtensions.Match(Matcher matcher, String rootDir, String file)
   at Program.<Main>$(String[] args)
Regression?

No

Known Workarounds

Check that rootDir != file before calling Match().

Configuration

Using 11.0.100-rc.3.26522.148 SDK to build. Unsure which runtime that means I am running.
Library version given in the sample.
Running on Ubuntu 24.04, x64.
I doubt the problem is configuration-specific, I believe it also repros on Windows.

Other information

Probably here: https://github.com/dotnet/runtime/blob/8f030f80c0dd2722eb2f618984e9db6784765963/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs#L94

Ngôn ngữ chính
C#
Star
18.4k
Fork
5.8k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
579

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/runtime

Tất cả issue của dotnet/runtime

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.