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

Fix accessing files via Java ClassLoader in JRuby #401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/json-schema/schema/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def read(location)
body = if uri.scheme.nil? || uri.scheme == 'file'
uri = JSON::Util::URI.file_uri(uri)
read_file(Pathname.new(uri.path).expand_path)
elsif uri.scheme == 'uri' && uri.path.start_with?("classloader:")
read_file(Pathname.new(uri).expand_path)
else
read_uri(uri)
end
Expand Down Expand Up @@ -128,7 +130,11 @@ def read_uri(uri)

def read_file(pathname)
if accept_file?(pathname)
File.read(JSON::Util::URI.unescaped_path(pathname.to_s))
if pathname.to_s.start_with?("uri:classloader:")
File.read(pathname.to_s)
else
File.read(JSON::Util::URI.unescaped_path(pathname.to_s))
end
else
raise JSON::Schema::ReadRefused.new(pathname.to_s, :file)
end
Expand Down
7 changes: 5 additions & 2 deletions lib/json-schema/util/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ def self.strip_fragment(uri)

def self.file_uri(uri)
parsed_uri = parse(uri)

Addressable::URI.convert_path(parsed_uri.path)
if parsed_uri.scheme
parsed_uri
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional would read better as if parsed_uri.scheme

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense. I'll edit the commit.

Addressable::URI.convert_path(parsed_uri.path)
end
end

def self.unescape_uri(uri)
Expand Down