Skip to content

Commit 39d0d03

Browse files
committed
Allow relative IRIs for @vocab
See w3c/json-ld-syntax#72
1 parent 52fd18f commit 39d0d03

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ld/context.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ func NewContext(values map[string]interface{}, options *JsonLdOptions) *Context
4242
termDefinitions: make(map[string]interface{}),
4343
}
4444

45+
context.values["@base"] = options.Base
46+
4547
if values != nil {
4648
for k, v := range values {
4749
context.values[k] = v
4850
}
4951
}
5052

51-
context.values["@base"] = options.Base
5253
context.values["processingMode"] = options.ProcessingMode
5354

5455
return context
@@ -185,6 +186,7 @@ func (c *Context) parse(localContext interface{}, remoteContexts []string, parsi
185186
if vocabValue == nil {
186187
delete(result.values, "@vocab")
187188
} else if vocabString, isString := vocabValue.(string); isString {
189+
188190
if IsAbsoluteIri(vocabString) {
189191
result.values["@vocab"] = vocabValue
190192
} else if vocabString == "" {
@@ -194,7 +196,11 @@ func (c *Context) parse(localContext interface{}, remoteContexts []string, parsi
194196
return nil, NewJsonLdError(InvalidVocabMapping, "@vocab is empty but @base is not specified")
195197
}
196198
} else {
197-
return nil, NewJsonLdError(InvalidVocabMapping, "@vocab must be an absolute IRI")
199+
expandedVocab, err := result.ExpandIri(vocabString, true, true, nil, nil)
200+
if err != nil {
201+
return nil, err
202+
}
203+
result.values["@vocab"] = expandedVocab
198204
}
199205
} else {
200206
return nil, NewJsonLdError(InvalidVocabMapping, "@vocab must be a string or null")

0 commit comments

Comments
 (0)