Skip to content

UriResolver doesn't handle Windows directory separators #258

Closed as not planned
@Cryszon

Description

@Cryszon

Regex in UriResolver->parse() doesn't correctly parse a file path if it contains Windows directory separators. This makes the $basePath become an empty string and breaks relative $refs.

// UriResolver->resolve($uri, $baseUri = null)
$baseComponents = $this->parse($baseUri); // $baseUri = "file://C:\code\my-schema.json"
$basePath = $baseComponents['path']; // $basePath is empty.

The \ directory separators are inserted when realpath() is called on a Windows platform. The regex doesn't necessarily need to be changed (although it is a bit messy and silently returns an empty path, which made the issue hard to debug). A simple workaround is to replace directory separators when resolving the initial schema file as illustrated below.

$schema = $refResolver->resolve('file://' . str_replace('\\', '/', realpath('schema.json'));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions