Skip to content

Commit df1abfc

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

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

src/Model/SchemaDefinition/SchemaDefinitionDictionary.php

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

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

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

222222
$dir = $currentDir;
223223
while (true) {
224-
$candidate = $absolutePathPrefix . $this->normalizePath($dir . '/' . $relative);
224+
$candidate = $dir . '/' . $relative;
225225
if (file_exists($candidate)) {
226226
return $candidate;
227227
}
@@ -235,23 +235,4 @@ private function getLocalRefPath(string $jsonSchemaFile): ?string
235235

236236
return null;
237237
}
238-
239-
private function normalizePath(string $path): string
240-
{
241-
$segments = explode('/', str_replace('\\', '/', $path));
242-
$output = [];
243-
244-
foreach ($segments as $seg) {
245-
if ($seg === '' || $seg === '.') {
246-
continue;
247-
}
248-
if ($seg === '..') {
249-
array_pop($output);
250-
continue;
251-
}
252-
$output[] = $seg;
253-
}
254-
255-
return str_replace('/', DIRECTORY_SEPARATOR, implode('/', $output));
256-
}
257238
}

0 commit comments

Comments
 (0)