Skip to content

Commit cdf7bcc

Browse files
committed
Add tests and fix for @vocab="" test case.
See json-ld/json-ld.org#603 for discussion.
1 parent afdfc1a commit cdf7bcc

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

ld/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ func (c *Context) parse(localContext interface{}, remoteContexts []string) (*Con
167167
} else if vocabString, isString := vocabValue.(string); isString {
168168
if IsAbsoluteIri(vocabString) {
169169
result.values["@vocab"] = vocabValue
170+
} else if vocabString == "" {
171+
if baseVal, hasBase := result.values["@base"]; hasBase {
172+
result.values["@vocab"] = baseVal
173+
} else {
174+
return nil, NewJsonLdError(InvalidVocabMapping, "@vocab is empty but @base is not specified")
175+
}
170176
} else {
171177
return nil, NewJsonLdError(InvalidVocabMapping, "@vocab must be an absolute IRI")
172178
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@base": "http://example.com/some/",
4+
"@vocab": ""
5+
}
6+
}

ld/testdata/compact-0095-in.jsonld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"@id": "http://example.com/some/deep/directory/and/relativePropertyIris",
4+
"http://example.com/absolute": [{"@value": "/absolute"}],
5+
"http://example.com/some/deep/directory/": [{"@value": "deep/directory"}],
6+
"http://example.com/some/deep/directory/and/": [{"@value": "deep/directory/and/"}],
7+
"http://example.com/some/#fragment-works": [{"@value": "#fragment-works"}],
8+
"http://example.com/some/?query=works": [{"@value": "?query=works"}],
9+
"http://example.com/some/link": [{"@value": "link"}],
10+
"http://example.com/some/../parent": [{"@value": "../parent"}],
11+
"http://example.com/too-many-dots": [{"@value": "too-many-dots"}]
12+
}
13+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"@context": {
3+
"@base": "http://example.com/some/",
4+
"@vocab": ""
5+
},
6+
"#fragment-works": "#fragment-works",
7+
"../parent": "../parent",
8+
"?query=works": "?query=works",
9+
"@id": "deep/directory/and/relativePropertyIris",
10+
"deep/directory/": "deep/directory",
11+
"deep/directory/and/": "deep/directory/and/",
12+
"http://example.com/absolute": "/absolute",
13+
"http://example.com/too-many-dots": "too-many-dots",
14+
"link": "link"
15+
}

ld/testdata/expand-0092-in.jsonld

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"@context": {
3+
"@base": "http://example.com/some/deep/directory/and/file/",
4+
"@vocab": ""
5+
},
6+
"@id": "relativePropertyIris",
7+
"link": "link",
8+
"#fragment-works": "#fragment-works",
9+
"?query=works": "?query=works",
10+
"./": "./",
11+
"../": "../",
12+
"../parent": "../parent",
13+
"../../parent-parent-eq-root": "../../parent-parent-eq-root",
14+
"../../../../../still-root": "../../../../../still-root",
15+
"../.././.././../../too-many-dots": "../.././.././../../too-many-dots",
16+
"/absolute": "/absolute",
17+
"//example.org/scheme-relative": "//example.org/scheme-relative"
18+
}

ld/testdata/expand-0092-out.jsonld

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"@id": "http://example.com/some/deep/directory/and/file/relativePropertyIris",
4+
"http://example.com/some/deep/directory/and/file/#fragment-works": [{"@value": "#fragment-works"}],
5+
"http://example.com/some/deep/directory/and/file/../": [{"@value": "../"}],
6+
"http://example.com/some/deep/directory/and/file/../../../../../still-root": [{"@value": "../../../../../still-root"}],
7+
"http://example.com/some/deep/directory/and/file/../.././.././../../too-many-dots": [{"@value": "../.././.././../../too-many-dots"}],
8+
"http://example.com/some/deep/directory/and/file/../../parent-parent-eq-root": [{"@value": "../../parent-parent-eq-root"}],
9+
"http://example.com/some/deep/directory/and/file/../parent": [{"@value": "../parent"}],
10+
"http://example.com/some/deep/directory/and/file/./": [{"@value": "./"}],
11+
"http://example.com/some/deep/directory/and/file///example.org/scheme-relative": [{"@value": "//example.org/scheme-relative"}],
12+
"http://example.com/some/deep/directory/and/file//absolute": [{"@value": "/absolute"}],
13+
"http://example.com/some/deep/directory/and/file/?query=works": [{"@value": "?query=works"}],
14+
"http://example.com/some/deep/directory/and/file/link": [{"@value": "link"}]
15+
}
16+
]

0 commit comments

Comments
 (0)