Skip to content

Commit

Permalink
Fix URI.intern from causing implicit #to_hash of a URI argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 30, 2016
1 parent 5a66f20 commit 146d7fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def self.cache
# @return [RDF::URI] an immutable, frozen URI object
def self.intern(*args)
str = args.first
args << {} unless args.last.is_a?(Hash) # FIXME: needed until #to_hash is removed to avoid DEPRECATION warning.
(cache[(str = str.to_s).to_sym] ||= self.new(*args)).freeze
end

Expand Down Expand Up @@ -200,10 +201,10 @@ def self.normalize_path(path)
end

##
# @overload URI(uri, options = {})
# @overload URI(uri, **options)
# @param [URI, String, #to_s] uri
#
# @overload URI(options = {})
# @overload URI(**options)
# @param [Hash{Symbol => Object}] options
# @option [String, #to_s] :scheme The scheme component.
# @option [String, #to_s] :user The user component.
Expand Down Expand Up @@ -281,7 +282,7 @@ def urn?
#
# @return [Boolean] `true` or `false`
# @see http://en.wikipedia.org/wiki/URI_scheme
# @see {NON_HIER_SCHEMES}
# @see NON_HIER_SCHEMES
# @since 1.0.10
def hier?
!NON_HIER_SCHEMES.include?(scheme)
Expand Down Expand Up @@ -1218,7 +1219,13 @@ def query_values=(value)
return
end

value = value.to_hash if value.respond_to?(:to_hash)
value = if value.respond_to?(:to_h)
value.to_h
elsif value.respond_to?(:to_hash)
value.to_hash
else
value
end
self.query = case value
when Array, Hash
value.map do |(k,v)|
Expand Down
4 changes: 4 additions & 0 deletions spec/model_uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
it "freezes instance" do
expect(RDF::URI.intern("a")).to be_frozen
end

it "does not use #to_hash given a URI" do
expect {RDF::URI.intern(RDF::URI("a"))}.not_to write.to(:error)
end
end

describe ".parse" do
Expand Down

0 comments on commit 146d7fb

Please sign in to comment.