@@ -160,12 +160,16 @@ void processConfig()
160160 string nextSoFar = soFar + Path . DirectorySeparatorChar + suitablePiece ;
161161 string curPath = p + nextSoFar ;
162162
163- if ( allowWildcards && ! File . Exists ( curPath ) && ! Directory . Exists ( curPath ) && curPath . Contains ( '*' ) && ( dirAuth == null || dirAuth ( request ) == null ) )
164- curPath = new DirectoryInfo ( p + soFar ) . GetFileSystemInfos ( suitablePiece ) . Select ( fs => fs . FullName ) . FirstOrDefault ( ) ?? curPath ;
163+ if ( allowWildcards && ! File . Exists ( curPath ) && ! Directory . Exists ( curPath ) && curPath . Contains ( '*' ) && ( dirAuth == null || dirAuth ( request ) == null )
164+ && new DirectoryInfo ( p + soFar ) . EnumerateFileSystemInfos ( suitablePiece ) . FirstOrDefault ( ) is { } newPiece )
165+ {
166+ nextSoFar = soFar + Path . DirectorySeparatorChar + newPiece . Name ;
167+ curPath = newPiece . FullName ;
168+ }
165169
166170 if ( File . Exists ( curPath ) )
167171 {
168- soFarUrl += "/" + new DirectoryInfo ( p + soFar ) . GetFiles ( suitablePiece ) [ 0 ] . Name . UrlEscape ( ) ;
172+ soFarUrl += "/" + new DirectoryInfo ( p + soFar ) . EnumerateFiles ( suitablePiece ) . First ( ) . Name . UrlEscape ( ) ;
169173
170174 if ( request . Url . Path != soFarUrl )
171175 return handleHeaderProcessor ( FileSystemResponseType . Redirect , HttpResponse . Redirect ( request . Url . WithPath ( soFarUrl ) ) ) ;
@@ -175,7 +179,15 @@ void processConfig()
175179 }
176180 else if ( Directory . Exists ( curPath ) )
177181 {
178- soFarUrl += "/" + new DirectoryInfo ( p + soFar ) . GetDirectories ( suitablePiece ) [ 0 ] . Name . UrlEscape ( ) ;
182+ var examinePiece = suitablePiece ;
183+ tryAgain :
184+ var dirs = new DirectoryInfo ( p + soFar ) . GetDirectories ( examinePiece ) ;
185+ if ( dirs . Length == 0 && examinePiece . EndsWith ( '.' ) )
186+ {
187+ examinePiece = examinePiece [ ..^ 1 ] ;
188+ goto tryAgain ;
189+ }
190+ soFarUrl += "/" + dirs [ 0 ] . Name . UrlEscape ( ) ;
179191 soFar = nextSoFar ;
180192 processConfig ( ) ;
181193 goto foundOne ;
@@ -187,7 +199,7 @@ void processConfig()
187199 return HttpResponse . Create ( File . Open ( file404 , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) , file404type , HttpStatusCode . _404_NotFound ) ;
188200 throw new HttpNotFoundException ( request . Url . WithPathOnly ( soFarUrl + "/" + piece ) . ToHref ( ) ) ;
189201
190- foundOne : ;
202+ foundOne : ;
191203 }
192204
193205 // If this point is reached, it’s a directory.
0 commit comments