Skip to content

Commit 146d7fb

Browse files
committed
Fix URI.intern from causing implicit #to_hash of a URI argument.
1 parent 5a66f20 commit 146d7fb

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

lib/rdf/model/uri.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def self.cache
143143
# @return [RDF::URI] an immutable, frozen URI object
144144
def self.intern(*args)
145145
str = args.first
146+
args << {} unless args.last.is_a?(Hash) # FIXME: needed until #to_hash is removed to avoid DEPRECATION warning.
146147
(cache[(str = str.to_s).to_sym] ||= self.new(*args)).freeze
147148
end
148149

@@ -200,10 +201,10 @@ def self.normalize_path(path)
200201
end
201202

202203
##
203-
# @overload URI(uri, options = {})
204+
# @overload URI(uri, **options)
204205
# @param [URI, String, #to_s] uri
205206
#
206-
# @overload URI(options = {})
207+
# @overload URI(**options)
207208
# @param [Hash{Symbol => Object}] options
208209
# @option [String, #to_s] :scheme The scheme component.
209210
# @option [String, #to_s] :user The user component.
@@ -281,7 +282,7 @@ def urn?
281282
#
282283
# @return [Boolean] `true` or `false`
283284
# @see http://en.wikipedia.org/wiki/URI_scheme
284-
# @see {NON_HIER_SCHEMES}
285+
# @see NON_HIER_SCHEMES
285286
# @since 1.0.10
286287
def hier?
287288
!NON_HIER_SCHEMES.include?(scheme)
@@ -1218,7 +1219,13 @@ def query_values=(value)
12181219
return
12191220
end
12201221

1221-
value = value.to_hash if value.respond_to?(:to_hash)
1222+
value = if value.respond_to?(:to_h)
1223+
value.to_h
1224+
elsif value.respond_to?(:to_hash)
1225+
value.to_hash
1226+
else
1227+
value
1228+
end
12221229
self.query = case value
12231230
when Array, Hash
12241231
value.map do |(k,v)|

spec/model_uri_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
it "freezes instance" do
1717
expect(RDF::URI.intern("a")).to be_frozen
1818
end
19+
20+
it "does not use #to_hash given a URI" do
21+
expect {RDF::URI.intern(RDF::URI("a"))}.not_to write.to(:error)
22+
end
1923
end
2024

2125
describe ".parse" do

0 commit comments

Comments
 (0)