Skip to content

Commit 6b6234c

Browse files
committed
cross platform path compatibility
1 parent 2f464e0 commit 6b6234c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Model/SchemaDefinition/SchemaDefinitionDictionary.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,18 @@ private function getLocalRefPath(string $jsonSchemaFile): ?string
210210
$jsonSchemaFile = str_replace('\\', '/', $jsonSchemaFile);
211211

212212
// relative paths to the current location
213-
if (!str_starts_with($jsonSchemaFile, '/')) {
213+
if (!preg_match('#^(?:[A-Za-z]:/|/)#', $jsonSchemaFile, $match)) {
214214
$candidate = $this->normalizePath($currentDir . '/' . $jsonSchemaFile);
215215
return file_exists($candidate) ? $candidate : null;
216216
}
217217

218+
$absolutePathPrefix = $match[0];
218219
// absolute paths: traverse up to find the context root directory
219-
$relative = ltrim($jsonSchemaFile, '/');
220+
$relative = substr($jsonSchemaFile, strlen($absolutePathPrefix));
220221

221222
$dir = $currentDir;
222223
while (true) {
223-
$candidate = $this->normalizePath($dir . '/' . $relative);
224+
$candidate = $absolutePathPrefix . $this->normalizePath($dir . '/' . $relative);
224225
if (file_exists($candidate)) {
225226
return $candidate;
226227
}

0 commit comments

Comments
 (0)