Skip to content

Commit a7f2ec7

Browse files
committed
Fix URI#join for path-rootless, which goes away when merged with a relative path.
1 parent 500d5d9 commit a7f2ec7

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/rdf/model/uri.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ def join(*uris)
431431
joined_parts[:query] = uri.query
432432
else
433433
# Merge path segments from section 5.2.3
434-
base_path = path.to_s.sub(/\/[^\/]*$/, '/')
434+
# Note that if the path includes no segments, the entire path is removed
435+
# > return a string consisting of the reference's path component appended to all but the last segment of the base URI's path (i.e., excluding any characters after the right-most "/" in the base URI path, or excluding the entire base URI path if it does not contain any "/" characters).
436+
base_path = path.to_s.include?('/') ? path.to_s.sub(/\/[^\/]*$/, '/') : ''
435437
joined_parts[:path] = self.class.normalize_path(base_path + uri.path)
436438
joined_parts[:query] = uri.query
437439
end

spec/model_uri_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@
606606
%w(http://a/bb/ccc/.. g#s) => "<http://a/bb/ccc/g#s>",
607607

608608
%w(file:///a/bb/ccc/d;p?q g) => "<file:///a/bb/ccc/g>",
609+
# merging rootless base URL paths (json-ld-api 397f48b959c4517fef55a7b2623ad432e923240c)
610+
%w(tag:example a) => "<tag:a>",
609611
}.each_pair do |(lhs, rhs), result|
610612
it "creates #{result} from <#{lhs}> and '#{rhs}'" do
611613
expect(RDF::URI.new(lhs).join(rhs.to_s).to_base).to eq result

0 commit comments

Comments
 (0)