Skip to content

FileLoader breaks on empty prefix #21

@MarcusSchwarz

Description

@MarcusSchwarz

Example:

$loader = new \Opis\JsonSchema\Loaders\File('', ['./']);
$validator = new Validator(null, $loader);
$result = $validator->schemaValidation($data, $schema);

expected behavior: $result->isValid() is either true or false

actual behavior:

Fatal error: Uncaught Opis\JsonSchema\Exception\SchemaNotFoundException: Schema '/tester.json' was not found or could not be loaded in ../vendor/opis/json-schema/src/Validator.php on line 416

Reason:
src/Loaders/File.php:54
strpos($uri, $this->prefix) breaks, if $this->prefix is empty

Bonus: The documentation is slightly incorrect, the constructor has to be called with an array as second parameter.
https://docs.opis.io/json-schema/1.x/php-loader.html -> "File loader"

$loader = new \Opis\JsonSchema\Loaders\File(
"http://example.com/",
"/path/to/schemas"
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions