@@ -99,16 +99,14 @@ public function directories(string|array $masks = ['*']): static
99
99
private function addMask (array $ masks , string $ mode ): static
100
100
{
101
101
foreach ($ masks as $ mask ) {
102
- $ mask = FileSystem:: unixSlashes ( $ mask) ;
102
+ $ orig = $ mask ;
103
103
if ($ mode === 'dir ' ) {
104
- $ mask = rtrim ($ mask , '/ ' );
104
+ $ mask = rtrim ($ mask , '/ \\ ' );
105
105
}
106
- if ($ mask === '' || ($ mode === 'file ' && str_ends_with ( $ mask, ' / ' ) )) {
106
+ if ($ mask === '' || ($ mode === 'file ' && $ mask !== $ orig )) {
107
107
throw new Nette \InvalidArgumentException ("Invalid mask ' $ mask' " );
108
108
}
109
- if (str_starts_with ($ mask , '**/ ' )) {
110
- $ mask = substr ($ mask , 3 );
111
- }
109
+ $ mask = preg_replace ('~\*\*[/ \\\\]~A ' , '' , $ mask );
112
110
$ this ->find [] = [$ mask , $ mode ];
113
111
}
114
112
return $ this ;
@@ -132,7 +130,7 @@ public function in(string|array $paths): static
132
130
public function from (string |array $ paths ): static
133
131
{
134
132
$ paths = is_array ($ paths ) ? $ paths : func_get_args (); // compatibility with variadic
135
- $ this ->addLocation ($ paths , ' / ** ' );
133
+ $ this ->addLocation ($ paths , DIRECTORY_SEPARATOR . ' ** ' );
136
134
return $ this ;
137
135
}
138
136
@@ -143,7 +141,7 @@ private function addLocation(array $paths, string $ext): void
143
141
if ($ path === '' ) {
144
142
throw new Nette \InvalidArgumentException ("Invalid directory ' $ path' " );
145
143
}
146
- $ path = rtrim (FileSystem:: unixSlashes ( $ path) , '/ ' );
144
+ $ path = rtrim ($ path , '/ \\ ' );
147
145
$ this ->in [] = $ path . $ ext ;
148
146
}
149
147
}
@@ -328,7 +326,6 @@ public function getIterator(): \Generator
328
326
if ($ item instanceof self) {
329
327
yield from $ item ->getIterator ();
330
328
} else {
331
- $ item = FileSystem::platformSlashes ($ item );
332
329
yield $ item => new FileInfo ($ item );
333
330
}
334
331
}
@@ -349,7 +346,7 @@ private function traverseDir(string $dir, array $searches, array $subdirs = []):
349
346
}
350
347
351
348
try {
352
- $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator:: UNIX_PATHS );
349
+ $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME );
353
350
} catch (\UnexpectedValueException $ e ) {
354
351
if ($ this ->ignoreUnreadableDirs ) {
355
352
return ;
@@ -358,7 +355,7 @@ private function traverseDir(string $dir, array $searches, array $subdirs = []):
358
355
}
359
356
}
360
357
361
- $ files = $ this ->convertToFiles ($ pathNames , implode (' / ' , $ subdirs ), FileSystem::isAbsolute ($ dir ));
358
+ $ files = $ this ->convertToFiles ($ pathNames , implode (DIRECTORY_SEPARATOR , $ subdirs ), FileSystem::isAbsolute ($ dir ));
362
359
363
360
if ($ this ->sort ) {
364
361
$ files = iterator_to_array ($ files );
@@ -404,9 +401,8 @@ private function convertToFiles(iterable $pathNames, string $relativePath, bool
404
401
{
405
402
foreach ($ pathNames as $ pathName ) {
406
403
if (!$ absolute ) {
407
- $ pathName = preg_replace ('~\.?/ ~A ' , '' , $ pathName );
404
+ $ pathName = preg_replace ('~\.?[ \\\\ /] ~A ' , '' , $ pathName );
408
405
}
409
- $ pathName = FileSystem::platformSlashes ($ pathName );
410
406
yield new FileInfo ($ pathName , $ relativePath );
411
407
}
412
408
}
@@ -440,7 +436,7 @@ private function buildPlan(): array
440
436
} else {
441
437
foreach ($ this ->in ?: ['. ' ] as $ in ) {
442
438
$ in = strtr ($ in , ['[ ' => '[[] ' , '] ' => '[]] ' ]); // in path, do not treat [ and ] as a pattern by glob()
443
- $ splits [] = self ::splitRecursivePart ($ in . ' / ' . $ mask );
439
+ $ splits [] = self ::splitRecursivePart ($ in . DIRECTORY_SEPARATOR . $ mask );
444
440
}
445
441
}
446
442
@@ -470,11 +466,11 @@ private function buildPlan(): array
470
466
*/
471
467
private static function splitRecursivePart (string $ path ): array
472
468
{
473
- $ a = strrpos ( $ path , ' / ' );
474
- $ parts = preg_split ('~(?<=^|/ )\*\*($|/ )~ ' , substr ( $ path , 0 , $ a + 1 ) , 2 );
469
+ preg_match ( ' ~(.*[ \\\\ /])(.*)$~A ' , $ path , $ m );
470
+ $ parts = preg_split ('~(?<=^|[ \\\\ /] )\*\*($|[ \\\\ /] )~ ' , $ m [ 1 ] , 2 );
475
471
return isset ($ parts [1 ])
476
- ? [$ parts [0 ], $ parts [1 ] . substr ( $ path , $ a + 1 ) , true ]
477
- : [$ parts [0 ], substr ( $ path , $ a + 1 ) , false ];
472
+ ? [$ parts [0 ], $ parts [1 ] . $ m [ 2 ] , true ]
473
+ : [$ parts [0 ], $ m [ 2 ] , false ];
478
474
}
479
475
480
476
@@ -483,6 +479,7 @@ private static function splitRecursivePart(string $path): array
483
479
*/
484
480
private function buildPattern (string $ mask ): string
485
481
{
482
+ $ mask = FileSystem::unixSlashes ($ mask );
486
483
if ($ mask === '* ' ) {
487
484
return '## ' ;
488
485
} elseif (str_starts_with ($ mask , './ ' )) {
0 commit comments