Skip to content

Commit e3e446e

Browse files
committed
Fix dir separator
1 parent a45ba1a commit e3e446e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Internal/Runtime/SourceExecutor.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,31 +333,44 @@ private function doInclude(Composite $token, ReadableInterface $src): iterable
333333
*/
334334
private function lookup(ReadableInterface $source, string $file, bool $withLocal): ReadableInterface
335335
{
336+
$file = $this->normalizeRelativePathname($file);
337+
336338
if ($source instanceof FileInterface && $withLocal) {
337-
$pathname = \dirname($source->getPathname()) . '/' . $file;
339+
$pathname = \dirname($source->getPathname()) . \DIRECTORY_SEPARATOR . $file;
338340

339341
if (\is_file($pathname)) {
340342
return File::fromPathname($pathname);
341343
}
342344
}
343345

344346
foreach ($this->directories as $directory) {
345-
$pathname = $directory . '/' . $file;
347+
$pathname = $directory . \DIRECTORY_SEPARATOR . $file;
346348

347349
if (\is_file($pathname)) {
348350
return File::fromPathname($pathname);
349351
}
350352
}
351353

352354
foreach ($this->sources as $name => $source) {
353-
if ($name === $file) {
355+
if ($this->normalizeRelativePathname($name) === $file) {
354356
return $source;
355357
}
356358
}
357359

358360
throw new \LogicException(\sprintf('"%s": No such file or directory', $file));
359361
}
360362

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+
361374
/**
362375
* @param Composite $token
363376
* @param ReadableInterface $source

0 commit comments

Comments
 (0)