Skip to content

Commit 95e07ef

Browse files
committed
Add expansion tests for compact IRIs having terms with trailing ':'.
1 parent 6a47234 commit 95e07ef

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/json/ld/context.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,19 @@ def expand_iri(value, documentRelative: false, vocab: false, local_context: nil,
993993
return RDF::Node.new(namer.get_sym(suffix)) if prefix == '_'
994994
return RDF::URI(value) if suffix[0,2] == '//'
995995

996-
# If local context is not null, it contains a key that equals prefix, and the value associated with the key that equals prefix in defined is not true, invoke the Create Term Definition algorithm, passing active context, local context, prefix as term, and defined. This will ensure that a term definition is created for prefix in active context during Context Processing.
997-
if local_context && local_context.has_key?(prefix) && !defined[prefix]
998-
create_term_definition(local_context, prefix, defined)
996+
# If local context is not null, it contains a key that equals prefix, or prefix followed by a ':', and the value associated with the key that equals prefix in defined is not true, invoke the Create Term Definition algorithm, passing active context, local context, prefix (possibly with an added ':') as term, and defined. This will ensure that a term definition is created for prefix in active context during Context Processing.
997+
if local_context
998+
if local_context.has_key?(prefix + ':') && !defined[prefix + ':']
999+
create_term_definition(local_context, prefix + ':', defined)
1000+
elsif local_context.has_key?(prefix) && !defined[prefix]
1001+
create_term_definition(local_context, prefix, defined)
1002+
end
9991003
end
10001004

1001-
# If active context contains a term definition for prefix, return the result of concatenating the IRI mapping associated with prefix and suffix.
1002-
result = if (td = term_definitions[prefix])
1005+
# If active context contains a term definition for prefix followed by ':', or prefix, return the result of concatenating the IRI mapping associated with prefix and suffix.
1006+
result = if (td = term_definitions[prefix + ':'])
1007+
result = td.id + suffix
1008+
elsif (td = term_definitions[prefix])
10031009
result = td.id + suffix
10041010
else
10051011
# (Otherwise) Return value as it is already an absolute IRI.

spec/context_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ def containers
747747
'@base' => 'http://base/',
748748
'@vocab' => 'http://vocab/',
749749
'ex' => 'http://example.org/',
750+
'colon:' => 'http://example.net/',
750751
'' => 'http://empty/',
751752
'_' => 'http://underscore/'
752753
})
@@ -771,6 +772,7 @@ def containers
771772
"absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
772773
"term" => ["ex", RDF::URI("ex")],
773774
"prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
775+
"colon:suffix" => ["colon:suffix", RDF::URI("http://example.net/suffix")],
774776
"keyword" => ["@type", "@type"],
775777
"empty" => [":suffix", RDF::URI("http://empty/suffix")],
776778
"unmapped" => ["foo", RDF::URI("foo")],
@@ -792,6 +794,7 @@ def containers
792794
"absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
793795
"term" => ["ex", RDF::URI("http://base/ex")],
794796
"prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
797+
"colon:suffix" => ["colon:suffix", RDF::URI("http://example.net/suffix")],
795798
"keyword" => ["@type", "@type"],
796799
"empty" => [":suffix", RDF::URI("http://empty/suffix")],
797800
"unmapped" => ["foo", RDF::URI("http://base/foo")],
@@ -813,6 +816,7 @@ def containers
813816
"absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
814817
"term" => ["ex", RDF::URI("http://example.org/")],
815818
"prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
819+
"colon:suffix" => ["colon:suffix", RDF::URI("http://example.net/suffix")],
816820
"keyword" => ["@type", "@type"],
817821
"empty" => [":suffix", RDF::URI("http://empty/suffix")],
818822
"unmapped" => ["foo", RDF::URI("http://vocab/foo")],

spec/expand_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,25 @@
8383
"@value with false" => {
8484
input: {"http://example.com/ex" => {"@value" => false}},
8585
output: [{"http://example.com/ex" => [{"@value" => false}]}]
86-
}
86+
},
87+
"compact IRI" => {
88+
input: {
89+
"@context" => {"ex" => "http://example.com/"},
90+
"ex:p" => {"@id" => "ex:Sub1"}
91+
},
92+
output: [{
93+
"http://example.com/p" => [{"@id" => "http://example.com/Sub1"}]
94+
}]
95+
},
96+
"compact IRI with term having trailing ':'" => {
97+
input: {
98+
"@context" => {"ex:" => "http://example.com/"},
99+
"ex:p" => {"@id" => "ex:Sub1"}
100+
},
101+
output: [{
102+
"http://example.com/p" => [{"@id" => "http://example.com/Sub1"}]
103+
}]
104+
},
87105
}.each_pair do |title, params|
88106
it(title) {run_expand params}
89107
end

0 commit comments

Comments
 (0)