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

Windows file based schema paths do not trigger accept_file for the SchemaReader #439

Open
glennsarti opened this issue Aug 19, 2019 · 0 comments

Comments

@glennsarti
Copy link

I am writing a Schema validator that can run on Linux (and Mac) and Windows platforms and I noticed something strange with the Schema Reader.

When I attempted to read a schema from disk on Windows it worked fine, but on Linux, I was getting ReadRefused Errors

Sample code

...
        # The schema should not query external references, except for the meta-schema
        schema_reader = ::JSON::Schema::Reader.new(
          accept_file: false,
          accept_uri:  proc { |uri| uri.host.nil? || ['json-schema.org'].include?(uri.host) },
        )
        @document_schema = schema_reader.read(@schema_file)
...

Where @schema_file is the absolute file path. On Linux for example /tmp/something/ and Windows C:/something

However it seems the logic used to detect URI vs file path is not setup for Windows paths correctly. https://github.com/ruby-json-schema/json-schema/blob/3f07ef0599c9a0e080840bfd1be04df433b7bbff/lib/json-schema/schema/reader.rb#L86

In a simple pry session:

[7] pry(#<JSON::Schema::Reader>)> JSON::Util::URI.parse('C:/something').scheme
=> "C"
[8] pry(#<JSON::Schema::Reader>)> JSON::Util::URI.parse('/tmp/something').scheme
=> nil
[9] pry(#<JSON::Schema::Reader>)>

The Windows paths appear as "URIs" instead of actual files on disk, therefore they never trigger the accept_file gating logic

The documentation for SchemaReader makes no mention of this behavior either.

How are we supposed to pass in Windows, and Linux, paths so that they get parsed correctly?

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

1 participant