Skip to content

Commit 962481a

Browse files
committed
Allow @base to be a relative IRI, which is called for in the spec, but not otherwise tested.
1 parent 1093e1a commit 962481a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/json/ld/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def empty?
198198
def base=(value)
199199
if value
200200
raise JsonLdError::InvalidBaseIRI, "@base must be a string: #{value.inspect}" unless value.is_a?(String) || value.is_a?(RDF::URI)
201-
@base = RDF::URI(value).dup
201+
@base = @base ? @base.join(value) : RDF::URI(value).dup
202202
@base.canonicalize!
203203
@base.fragment = nil
204204
@base.query = nil

spec/context_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,28 @@ def containers
603603

604604
end
605605

606+
describe "#base=" do
607+
subject {
608+
context.parse({
609+
'@base' => 'http://base/',
610+
'@vocab' => 'http://vocab/',
611+
'ex' => 'http://example.org/',
612+
'' => 'http://empty/',
613+
'_' => 'http://underscore/'
614+
})
615+
}
616+
617+
it "sets new base uri given an absolute uri" do
618+
subject.base = "http://example.org/"
619+
expect(subject.base).to eql RDF::URI("http://example.org/")
620+
end
621+
622+
it "sets relative URI" do
623+
subject.base = "foo/bar"
624+
expect(subject.base).to eql RDF::URI("http://base/foo/bar")
625+
end
626+
end
627+
606628
describe "#expand_iri" do
607629
subject {
608630
context.parse({

0 commit comments

Comments
 (0)