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

オープン 初心者向け
#136,989 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@makazeu がすでに取り組んでいます。

2026年11月5日 から。

  • #137020 @makazeu による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
backend

調査の方向性

まず src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs、特に issue でリンクされている EnumerateFileSystemInfos のコードを確認してください。rootDir と file が同じパスになる、提供されたファイルベースのアプリで障害を再現し、その後、関連する FileSystemGlobbing のテストを調べてください。このケースで例外をスローせずに Match() が HasMatches == false を返せば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
C#
スター
18.4k
フォーク
5.8k
平均マージ
2日 17時間
マージ済み PR(30日)
581

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/runtime のほかの issue

dotnet/runtime の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。