Skip to content

Commit 7ea4698

Browse files
committed
Can't lookup a vocabulary from a BNode.
1 parent cb2ec01 commit 7ea4698

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/rdf/vocabulary.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ def expand_pname(pname)
304304
# @param [RDF::URI] uri
305305
# @return [Vocabulary]
306306
def find(uri)
307+
uri = RDF::URI(uri) if uri.is_a?(String)
308+
return nil unless uri.uri? && uri.valid?
307309
RDF::Vocabulary.detect do |v|
308310
if uri.length >= v.to_uri.length
309-
RDF::URI(uri).start_with?(v.to_uri)
311+
uri.start_with?(v.to_uri)
310312
else
311313
v.to_uri.to_s.sub(%r([/#]$), '') == uri.to_s
312314
end

spec/vocabulary_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@
324324
expect(RDF::Vocabulary.find(term.to_s)).to equal vocab
325325
end
326326
end
327+
it "returns nil if argument is a BNode" do
328+
terms.each do |term, vocab|
329+
expect(RDF::Vocabulary.find(RDF::Node.new("a"))).to be_nil
330+
end
331+
end
332+
it "returns nil if argument an invalid URI" do
333+
terms.each do |term, vocab|
334+
expect(RDF::Vocabulary.find("a b c")).to be_nil
335+
end
336+
end
327337
end
328338

329339
describe ".find_term" do

0 commit comments

Comments
 (0)