Skip to content

Commit

Permalink
Rename normalize_uri to normalized_uri back
Browse files Browse the repository at this point in the history
  • Loading branch information
bolshakov committed Jul 6, 2024
1 parent b1c7d92 commit 8452324
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/json-schema/util/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/uri_util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -24,31 +24,31 @@ 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
str = '/foo/bar.json'
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
str = 'foo/bar.json'
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
str = 'file://localhost/foo/bar.json'
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
Expand Down

0 comments on commit 8452324

Please sign in to comment.