From 8452324a9fb5c34c87d500f813d3e3c8ec609056 Mon Sep 17 00:00:00 2001 From: Tema Bolshakov Date: Sat, 6 Jul 2024 18:52:45 +0200 Subject: [PATCH] Rename normalize_uri to normalized_uri back --- lib/json-schema/util/uri.rb | 6 +++--- lib/json-schema/validator.rb | 10 +++++----- test/uri_util_test.rb | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/json-schema/util/uri.rb b/lib/json-schema/util/uri.rb index fad8e709..72542fca 100644 --- a/lib/json-schema/util/uri.rb +++ b/lib/json-schema/util/uri.rb @@ -37,8 +37,8 @@ def strip_fragment(uri) # @param uri [String, Addressable::URI] # @return [Addressable::URI] - def normalize_uri(uri, base_path = Dir.pwd) - parse(uri).normalize_uri(base_path) + def normalized_uri(uri, base_path = Dir.pwd) + parse(uri).normalized_uri(base_path) end # Normalizes the reference URI based on the provided base URI @@ -122,7 +122,7 @@ def absolutize_ref(base) if ref.absolute? ref else - self.class.strip_fragment(base).join(ref.path).normalize_uri + self.class.strip_fragment(base).join(ref.path).normalized_uri end end end diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 63127df4..8b034cb3 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -321,7 +321,7 @@ def schema_loaded?(schema_uri) end def schema_key_for(uri) - key = Util::URI.normalize_uri(uri).to_s + key = Util::URI.normalized_uri(uri).to_s key.end_with?('#') ? key : "#{key}#" end @@ -534,7 +534,7 @@ def initialize_schema(schema, default_validator) self.class.add_schema(schema) rescue JSON::Schema::JsonParseError # Build a uri for it - schema_uri = Util::URI.normalize_uri(schema) + schema_uri = Util::URI.normalized_uri(schema) if !self.class.schema_loaded?(schema_uri) schema = @options[:schema_reader].read(schema_uri) schema = JSON::Schema.stringify(schema) @@ -574,7 +574,7 @@ def initialize_data(data) if @options[:json] data = self.class.parse(data) elsif @options[:uri] - json_uri = Util::URI.normalize_uri(data) + json_uri = Util::URI.normalized_uri(data) data = self.class.parse(custom_open(json_uri)) elsif data.is_a?(String) begin @@ -583,7 +583,7 @@ def initialize_data(data) data = strict_convert ? data : self.class.parse(data) rescue JSON::Schema::JsonParseError begin - json_uri = Util::URI.normalize_uri(data) + json_uri = Util::URI.normalized_uri(data) data = self.class.parse(custom_open(json_uri)) rescue JSON::Schema::JsonLoadError, JSON::Schema::UriError # Silently discard the error - use the data as-is @@ -595,7 +595,7 @@ def initialize_data(data) end def custom_open(uri) - uri = Util::URI.normalize_uri(uri) if uri.is_a?(String) + uri = Util::URI.normalized_uri(uri) if uri.is_a?(String) if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme) begin URI.open(uri.to_s).read diff --git a/test/uri_util_test.rb b/test/uri_util_test.rb index 40dd031a..2c66d10f 100644 --- a/test/uri_util_test.rb +++ b/test/uri_util_test.rb @@ -6,7 +6,7 @@ def test_normalized_uri uri = Addressable::URI.new(scheme: 'https', host: 'www.google.com', path: 'search',) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_with_empty_fragment @@ -15,7 +15,7 @@ def test_normalized_uri_with_empty_fragment host: 'www.google.com', path: 'search', fragment: nil,) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_with_fragment @@ -24,7 +24,7 @@ def test_normalized_uri_with_fragment host: 'www.google.com', path: 'search', fragment: 'foo',) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_absolute_path @@ -32,7 +32,7 @@ def test_normalized_uri_for_absolute_path uri = Addressable::URI.new(scheme: 'file', host: '', path: '/foo/bar.json',) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_relative_path @@ -40,7 +40,7 @@ def test_normalized_uri_for_relative_path uri = Addressable::URI.new(scheme: 'file', host: '', path: '/home/foo/bar.json',) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_normalized_uri_for_file_path_with_host @@ -48,7 +48,7 @@ def test_normalized_uri_for_file_path_with_host uri = Addressable::URI.new(scheme: 'file', host: 'localhost', path: '/foo/bar.json',) - assert_equal uri, JSON::Util::URI.normalize_uri(str, '/home') + assert_equal uri, JSON::Util::URI.normalized_uri(str, '/home') end def test_uri_parse