Skip to content

Commit

Permalink
Merge pull request #77 from piprate/fix-nested-context
Browse files Browse the repository at this point in the history
Fix #76: Nested @context definition returns an error
  • Loading branch information
kazarena authored Oct 30, 2023
2 parents 207e3e3 + dfba40f commit 257ca0d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ld/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func (c *Context) parse(localContext interface{}, remoteContexts []string, parsi
return nil, NewJsonLdError(InvalidLocalContext, context)
}

// dereference @context key if present
if nestedContext := contextMap["@context"]; nestedContext != nil {
contextMap, isMap = nestedContext.(map[string]interface{})
if !isMap {
return nil, NewJsonLdError(InvalidLocalContext, nestedContext)
}
}

pm, hasProcessingMode := c.values["processingMode"]

if versionValue, versionPresent := contextMap["@version"]; versionPresent {
Expand Down
5 changes: 3 additions & 2 deletions ld/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ func TestSuite(t *testing.T) {
manifestList = append(manifestList, filepath.Join(testDir, val.(string)))
}

// Framing and Normalisation test suites

manifestList = append(manifestList,
// Framing and Normalisation test suites
filepath.Join(testDir, "frame-manifest.jsonld"),
filepath.Join(testDir, "normalization", "manifest-urgna2012.jsonld"),
filepath.Join(testDir, "normalization", "manifest-urdna2015.jsonld"),
// extra tests that aren't covered by the official test suite
filepath.Join(testDir, "extra-manifest.jsonld"),
)

dl := NewDefaultDocumentLoader(nil)
Expand Down
18 changes: 18 additions & 0 deletions ld/testdata/extra-manifest.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"@context": ["context.jsonld", {"@base": "extra-manifest"}],
"@id": "",
"@type": "mf:Manifest",
"name": "Expansion",
"description": "JSON-LD Expansion tests.",
"baseIri": "https://w3c.github.io/json-ld-api/tests/",
"sequence": [
{
"@id": "#ext0001",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "resolve nested contexts #76",
"purpose": "Ensure nested contexts are dereferenced",
"input": "extra/0001-in.jsonld",
"expect": "extra/0001-out.jsonld"
}
]
}
11 changes: 11 additions & 0 deletions ld/testdata/extra/0001-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@context": [
{
"@context": {
"PropertyValue": "http://schema.org/#PropertyValue"
}
}
],
"@id":"https://foo.bar/baz",
"@type":"PropertyValue"
}
8 changes: 8 additions & 0 deletions ld/testdata/extra/0001-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"@id": "https://foo.bar/baz",
"@type": [
"http://schema.org/#PropertyValue"
]
}
]

0 comments on commit 257ca0d

Please sign in to comment.