@@ -333,31 +333,44 @@ private function doInclude(Composite $token, ReadableInterface $src): iterable
333
333
*/
334
334
private function lookup (ReadableInterface $ source , string $ file , bool $ withLocal ): ReadableInterface
335
335
{
336
+ $ file = $ this ->normalizeRelativePathname ($ file );
337
+
336
338
if ($ source instanceof FileInterface && $ withLocal ) {
337
- $ pathname = \dirname ($ source ->getPathname ()) . ' / ' . $ file ;
339
+ $ pathname = \dirname ($ source ->getPathname ()) . \ DIRECTORY_SEPARATOR . $ file ;
338
340
339
341
if (\is_file ($ pathname )) {
340
342
return File::fromPathname ($ pathname );
341
343
}
342
344
}
343
345
344
346
foreach ($ this ->directories as $ directory ) {
345
- $ pathname = $ directory . ' / ' . $ file ;
347
+ $ pathname = $ directory . \ DIRECTORY_SEPARATOR . $ file ;
346
348
347
349
if (\is_file ($ pathname )) {
348
350
return File::fromPathname ($ pathname );
349
351
}
350
352
}
351
353
352
354
foreach ($ this ->sources as $ name => $ source ) {
353
- if ($ name === $ file ) {
355
+ if ($ this -> normalizeRelativePathname ( $ name) === $ file ) {
354
356
return $ source ;
355
357
}
356
358
}
357
359
358
360
throw new \LogicException (\sprintf ('"%s": No such file or directory ' , $ file ));
359
361
}
360
362
363
+ /**
364
+ * @param string $file
365
+ * @return string
366
+ */
367
+ private function normalizeRelativePathname (string $ file ): string
368
+ {
369
+ $ file = \trim ($ file , " \t\n\r\0\x0B/ \\" );
370
+
371
+ return \str_replace (['\\' , '/ ' ], \DIRECTORY_SEPARATOR , $ file );
372
+ }
373
+
361
374
/**
362
375
* @param Composite $token
363
376
* @param ReadableInterface $source
0 commit comments