@@ -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
}
@@ -329,7 +327,6 @@ public function getIterator(): \Generator
329
327
if ($ item instanceof self) {
330
328
yield from $ item ->getIterator ();
331
329
} else {
332
- $ item = FileSystem::platformSlashes ($ item );
333
330
yield $ item => new FileInfo ($ item );
334
331
}
335
332
}
@@ -350,7 +347,7 @@ private function traverseDir(string $dir, array $searches, array $subdirs = []):
350
347
}
351
348
352
349
try {
353
- $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator:: UNIX_PATHS );
350
+ $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME );
354
351
} catch (\UnexpectedValueException $ e ) {
355
352
if ($ this ->ignoreUnreadableDirs ) {
356
353
return ;
@@ -359,7 +356,7 @@ private function traverseDir(string $dir, array $searches, array $subdirs = []):
359
356
}
360
357
}
361
358
362
- $ files = $ this ->convertToFiles ($ pathNames , implode (' / ' , $ subdirs ), FileSystem::isAbsolute ($ dir ));
359
+ $ files = $ this ->convertToFiles ($ pathNames , implode (DIRECTORY_SEPARATOR , $ subdirs ), FileSystem::isAbsolute ($ dir ));
363
360
364
361
if ($ this ->sort ) {
365
362
$ files = iterator_to_array ($ files );
@@ -405,9 +402,8 @@ private function convertToFiles(iterable $pathNames, string $relativePath, bool
405
402
{
406
403
foreach ($ pathNames as $ pathName ) {
407
404
if (!$ absolute ) {
408
- $ pathName = preg_replace ('~\.?/ ~A ' , '' , $ pathName );
405
+ $ pathName = preg_replace ('~\.?[ \\\\ /] ~A ' , '' , $ pathName );
409
406
}
410
- $ pathName = FileSystem::platformSlashes ($ pathName );
411
407
yield new FileInfo ($ pathName , $ relativePath );
412
408
}
413
409
}
@@ -441,7 +437,7 @@ private function buildPlan(): array
441
437
} else {
442
438
foreach ($ this ->in ?: ['. ' ] as $ in ) {
443
439
$ in = strtr ($ in , ['[ ' => '[[] ' , '] ' => '[]] ' ]); // in path, do not treat [ and ] as a pattern by glob()
444
- $ splits [] = self ::splitRecursivePart ($ in . ' / ' . $ mask );
440
+ $ splits [] = self ::splitRecursivePart ($ in . DIRECTORY_SEPARATOR . $ mask );
445
441
}
446
442
}
447
443
@@ -471,11 +467,11 @@ private function buildPlan(): array
471
467
*/
472
468
private static function splitRecursivePart (string $ path ): array
473
469
{
474
- $ a = strrpos ( $ path , ' / ' );
475
- $ parts = preg_split ('~(?<=^|/ )\*\*($|/ )~ ' , substr ( $ path , 0 , $ a + 1 ) , 2 );
470
+ preg_match ( ' ~(.*[ \\\\ /])(.*)$~A ' , $ path , $ m );
471
+ $ parts = preg_split ('~(?<=^|[ \\\\ /] )\*\*($|[ \\\\ /] )~ ' , $ m [ 1 ] , 2 );
476
472
return isset ($ parts [1 ])
477
- ? [$ parts [0 ], $ parts [1 ] . substr ( $ path , $ a + 1 ) , true ]
478
- : [$ parts [0 ], substr ( $ path , $ a + 1 ) , false ];
473
+ ? [$ parts [0 ], $ parts [1 ] . $ m [ 2 ] , true ]
474
+ : [$ parts [0 ], $ m [ 2 ] , false ];
479
475
}
480
476
481
477
@@ -484,6 +480,7 @@ private static function splitRecursivePart(string $path): array
484
480
*/
485
481
private function buildPattern (string $ mask ): string
486
482
{
483
+ $ mask = FileSystem::unixSlashes ($ mask );
487
484
if ($ mask === '* ' ) {
488
485
return '## ' ;
489
486
} elseif (str_starts_with ($ mask , './ ' )) {
0 commit comments