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

Abierto Apto para principiantes
#136,989 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@makazeu ya está trabajando en esto.

Desde el 5/11/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp
Área
backend

Línea de trabajo

Empieza por src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs, especialmente el código de EnumerateFileSystemInfos enlazado en el issue. Reproduce el fallo con la aplicación proporcionada basada en archivos, donde rootDir y file son la misma ruta, y luego revisa las pruebas relacionadas de FileSystemGlobbing. El trabajo estará terminado cuando Match() devuelva HasMatches == false sin lanzar una excepción en este caso.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C#
Estrellas
18.4k
Forks
5.8k
Merge medio
2 d 17 h
PR fusionados (30 d)
581

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/runtime

Todos los issues de dotnet/runtime

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.