Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI Resolver not resolving absolute file paths correctly #17

Closed
georgeholt opened this issue Oct 19, 2012 · 2 comments
Closed

URI Resolver not resolving absolute file paths correctly #17

georgeholt opened this issue Oct 19, 2012 · 2 comments

Comments

@georgeholt
Copy link

Attempting to validate against a schema which extends another schema at say:

/path/to/abstract/schema.json

...throws a UriResolverException, stating that it's was unable to resolve the URI from base ''.

I'm not sure if I have to set a base somewhere, or if every schema requires an id (I see the code tries to use an id property as base if it's defined), but from my testing I can fix it by doing the following:

// src/JsonSchema/Uri/UriResolver.php:27
public function parse($uri)
{
    preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);

    $components = array();
    if (5 < count($match)) {
        $components =  array(
            'scheme'   => empty($match[2]) ? 'file' : $match[2], // Default the scheme to file://
            'authority' => $match[4],
            'path'         => empty($match[5]) ? '/' : $match[5]           // Default the path to /
        );
    } 
    if (7 < count($match)) {
        $components['query'] = $match[7];
    }
    if (9 < count($match)) {
        $components['fragment'] = $match[9];
    }

    return $components;
}

From what I can tell, when the resolve function is called with an empty base, then the condition on line 109 is met, causing the exception. This is because parsing the base (which in this case is empty) returns an empty path, meaning the number of basePathSegments will be zero.

@janmentzel
Copy link

have a look at #48 maybe the issue will be fixed by my pull request.
If want to try out before, you can checkout my fork hypercharge/json-schema

@bighappyface
Copy link
Collaborator

Closed with #174

Please re-open if that is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants