From 059d37230f8b14b4c72e01953210f2539630fe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20=C5=A0ev=C4=8D=C3=ADk?= Date: Wed, 1 Nov 2017 15:09:40 +0100 Subject: [PATCH 1/2] Fix file_uri for files already in proper URI Fixes access to files accessed through Java ClassLoader in JRuby --- lib/json-schema/util/uri.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/json-schema/util/uri.rb b/lib/json-schema/util/uri.rb index 9f7a3104..53d3a0f0 100644 --- a/lib/json-schema/util/uri.rb +++ b/lib/json-schema/util/uri.rb @@ -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 not parsed_uri.scheme.nil? + parsed_uri + else + Addressable::URI.convert_path(parsed_uri.path) + end end def self.unescape_uri(uri) From a076b1da61a3a96556ca008ed9ec565e4bbda809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20=C5=A0ev=C4=8D=C3=ADk?= Date: Wed, 1 Nov 2017 15:10:35 +0100 Subject: [PATCH 2/2] Add second condition for specific JRuby URI in schema reader --- lib/json-schema/schema/reader.rb | 8 +++++++- lib/json-schema/util/uri.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/json-schema/schema/reader.rb b/lib/json-schema/schema/reader.rb index a4eb664a..40a44718 100644 --- a/lib/json-schema/schema/reader.rb +++ b/lib/json-schema/schema/reader.rb @@ -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 @@ -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 diff --git a/lib/json-schema/util/uri.rb b/lib/json-schema/util/uri.rb index 53d3a0f0..e9ceaa0a 100644 --- a/lib/json-schema/util/uri.rb +++ b/lib/json-schema/util/uri.rb @@ -87,7 +87,7 @@ def self.strip_fragment(uri) def self.file_uri(uri) parsed_uri = parse(uri) - if not parsed_uri.scheme.nil? + if parsed_uri.scheme parsed_uri else Addressable::URI.convert_path(parsed_uri.path)