Skip to content

Commit 7374dff

Browse files
committed
Add version announcement requirement. Version must be set explicitly either using processingMode API option set to "json-ld-1.1", or "@Version": 1.1 in the first encountered JSON Object context, otherwise processing mode set implicitly to "json-ld-1.0". Added checks with expected errors in context processing if new features used in context with the wrong processing mode. Also adds compact/expand tests to check for proper error reporting.
Fixes #446.
1 parent 5f8becd commit 7374dff

14 files changed

+220
-14
lines changed

spec/latest/common/terms.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ <h1>General Terminology</h1>
212212
A <a>prefix</a> is a <a>term</a> that expands to a vocabulary <a>base IRI</a>. It
213213
is typically used along with a <em>suffix</em> to form a <a>compact IRI</a> to create an IRI
214214
within a vocabulary.</dd>
215+
<dt><dfn>processing mode</dfn></dt><dd>
216+
The processing mode defines how a JSON-LD document is processed.
217+
By default, all documents are assumed to be conformat with
218+
<a data-cite="JSON-LD-20140116">JSON-LD 1.0</a> [[!JSON-LD-20140116]]. By defining
219+
a different version using the <code>@version</code> member in a
220+
<a>context</a>, or via explicit API option, other processing modes
221+
can be accessed. This specification defines extensions for the
222+
<code>json-ld-1.1</code> <a>processing mode</a>.</dd>
215223
<dt><dfn data-lt="properties">property</dfn></dt><dd>
216224
The <a>IRI</a> label of an edge in a <a>linked data graph</a>.
217225
See <dfn data-cite="RDF11-CONCEPTS#dfn-predicate" data-lt="predicate|predicates|RDF predicates">RDF predicate</dfn> in [[RDF11-CONCEPTS]].</dd>

spec/latest/json-ld-api/index.html

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ <h1>Features</h1>
246246
transformations of JSON-LD documents. They are referred to as
247247
<a>expansion</a> and <a>compaction</a>, respectively.</p>
248248

249+
<p class="changed">JSON-LD 1.1 introduces new features that are
250+
compatible with <a data-cite="JSON-LD-20140116">JSON-LD 1.0</a> [[!JSON-LD-20140116]],
251+
but if processed by a JSON-LD 1.0 processor may produce different results.
252+
In order to detect this JSON-LD 1.1 requires that the <a>processing
253+
mode</a> be explicitly set to <code>json-ld-1.1</code>, either through the
254+
<a data-link-for="JsonLdOptions">processingMode</a> API option, or using the
255+
<code>@version</code> member within a <a>context</a>.</p>
256+
249257
<p>There are four major types of transformation that are discussed in this
250258
document: expansion, compaction, flattening, and RDF serialization/deserialization.</p>
251259

@@ -656,6 +664,12 @@ <h3>Overview</h3>
656664
a combination of the two. Finally we process each <a>context</a> contained
657665
in the <a>local context</a> <a>array</a> as follows.</p>
658666

667+
<p class="changed">Unless specified using
668+
<a data-link-for="JsonLdOptions">processingMode</a> API option, the first
669+
<a>context</a> parsed which is a <a>JSON object</a> determines
670+
sets the <a>processing mode</a> and
671+
affects the behavior of <a>expansion</a> and <a>compaction</a> algorithms.</p>
672+
659673
<p>If <a>context</a> is a <a>string</a>, it represents a reference to
660674
a remote context. We dereference the remote context and replace <a>context</a>
661675
with the value of the <code>@context</code> key of the top-level object in the
@@ -767,6 +781,20 @@ <h3>Algorithm</h3>
767781
error has been detected and processing is aborted.</li>
768782
</ol>
769783
</li>
784+
<li class="changed">If <em>context</em> has an <code>@version</code> key:
785+
<ol class="algorithm">
786+
<li>If the associated value is not <code>1.1</code>,
787+
an <a data-link-for="JsonLdErrorCode">invalid @version value</a>
788+
has been detected, and processing is aborted.</li>
789+
<li>If <a>processing mode</a>
790+
is not set, and <code>json-ld-1.1</code> is not a prefix
791+
of <a>processing mode</a>,
792+
a <a data-link-for="JsonLdErrorCode">processing mode conflict</a>
793+
error has been detected and processing is aborted.</li>
794+
<li>Set <a>processing mode</a>,
795+
to <code>json-ld-1.1</code>, if not already set.</li>
796+
</ol>
797+
</li>
770798
<li>If <em>context</em> has an <code>@vocab</code> key:
771799
<ol class="algorithm">
772800
<li>Initialize <em>value</em> to the value associated with the
@@ -794,6 +822,8 @@ <h3>Algorithm</h3>
794822
error has been detected and processing is aborted.</li>
795823
</ol>
796824
</li>
825+
<li class="changed">Set <a>processing mode</a>,
826+
to <code>json-ld-1.0</code>, if not already set.</li>
797827
<li>Create a <a>JSON object</a> <em>defined</em> to use to keep
798828
track of whether or not a <a>term</a> has already been defined
799829
or currently being defined during recursion.</li>
@@ -991,12 +1021,19 @@ <h3>Algorithm</h3>
9911021
or <code>@language</code>. Otherwise, an
9921022
<a data-link-for="JsonLdErrorCode">invalid container mapping</a>
9931023
has been detected and processing is aborted.</li>
1024+
<li class="changed">If processingMode is <code>json-ld-1.0</code> and the container value
1025+
is <code>@id</code> or <code>@type</code>, an
1026+
<a data-link-for="JsonLdErrorCode">invalid container mapping</a>
1027+
has been detected and processing is aborted.</li>
9941028
<li>Set the <a>container mapping</a> of <em>definition</em> to
9951029
<em>container</em>.</li>
9961030
</ol>
9971031
</li>
9981032
<li class="changed">If <em>value</em> contains the key <code>@context</code>:
9991033
<ol class="algorithm">
1034+
<li>If processingMode is <code>json-ld-1.0</code>, an
1035+
<a data-link-for="JsonLdErrorCode">invalid term definition</a>
1036+
has been detected and processing is aborted.</li>
10001037
<li>Initialize <em>context</em> to the value associated with the
10011038
<code>@context</code> key, which is treated as a <a>local context</a>.</li>
10021039
<li>Invoke the <a href="#context-processing-algorithm">Context Processing algorithm</a>
@@ -1022,6 +1059,9 @@ <h3>Algorithm</h3>
10221059
</li>
10231060
<li class="changed">If <em>value</em> contains the key <code>@nest</code>:
10241061
<ol class="algorithm">
1062+
<li>If processingMode is <code>json-ld-1.0</code>, an
1063+
<a data-link-for="JsonLdErrorCode">invalid term definition</a>
1064+
has been detected and processing is aborted.</li>
10251065
<li>Initialize <em>nest</em> to the value associated with the
10261066
<code>@nest</code> key, which must be a <a>string</a> and
10271067
must not be a keyword other than <code>@nest</code>. Otherwise, an
@@ -1234,7 +1274,7 @@ <h3>Algorithm</h3>
12341274
<code>@embed</code>, <code>@explicit</code>, <code>@omitDefault</code>, or
12351275
<code>@requireAll</code>) which are preserved through expansion.
12361276
Special processing for a <a>JSON-LD Frame</a> is invoked when the
1237-
<a data-link-for="JsonLdOptions">processingMode</a> API option is set
1277+
<a>processing mode</a> is set
12381278
to <code>json-ld-1.1-expand-frame</code>, indicated in the algorithm
12391279
with the <code>frame expansion</code> flag.</p>
12401280

@@ -4053,7 +4093,7 @@ <h3>The JsonLdOptions Type</h3>
40534093
LoadDocumentCallback documentLoader = null;
40544094
(object? or DOMString) expandContext = null;
40554095
boolean produceGeneralizedRdf = true;
4056-
DOMString processingMode = "json-ld-1.1";
4096+
DOMString processingMode = null;
40574097
};
40584098
--></pre>
40594099

@@ -4076,8 +4116,10 @@ <h3>The JsonLdOptions Type</h3>
40764116
<dd>If set to <code>true</code>, the JSON-LD processor may emit blank nodes for
40774117
<a>triple</a> <a>predicates</a>, otherwise they will be omitted.</dd>
40784118
<dt><dfn data-dfn-for="JsonLdOptions">processingMode</dfn></dt>
4079-
<dd>If set to <code>json-ld-1.1</code>, the implementation has to produce
4080-
exactly the same results as the algorithms defined in this specification.
4119+
<dd>Sets the <a>processing mode</a>.
4120+
If set to <code>json-ld-1.0</code> or <code>json-ld-1.1</code>, the
4121+
implementation must produce exactly the same results as the algorithms
4122+
defined in this specification.
40814123
If set to another value, the JSON-LD processor is allowed to extend
40824124
or modify the algorithms defined in this specification to enable
40834125
application-specific optimizations. The definition of such
@@ -4196,6 +4238,7 @@ <h4>JsonLdErrorCode</h4>
41964238
"invalid @index value",
41974239
"invalid @nest value",
41984240
"invalid @reverse value",
4241+
"invalid @version value",
41994242
"invalid base IRI",
42004243
"invalid container mapping",
42014244
"invalid default language",
@@ -4224,6 +4267,7 @@ <h4>JsonLdErrorCode</h4>
42244267
"loading document failed",
42254268
"loading remote context failed",
42264269
"multiple context link headers",
4270+
"processing mode conflict",
42274271
"recursive context inclusion"
42284272
};
42294273
--></pre>
@@ -4251,6 +4295,9 @@ <h4>JsonLdErrorCode</h4>
42514295
<dt><dfn>invalid @reverse value</dfn></dt>
42524296
<dd>An invalid value for an <code>@reverse</code> member has been detected,
42534297
i.e., the value was not a <a>JSON object</a>.</dd>
4298+
<dt><dfn>invalid @version value</dfn></dt>
4299+
<dd>The <code>@version</code> key was used in a <a>context</a> with
4300+
an out of range value.</dd>
42544301
<dt><dfn>invalid base IRI</dfn></dt>
42554302
<dd>An invalid <a>base IRI</a> has been detected, i.e., it is
42564303
neither an <a>absolute IRI</a> nor <code>null</code>.</dd>
@@ -4335,6 +4382,9 @@ <h4>JsonLdErrorCode</h4>
43354382
<dd>Multiple HTTP Link Headers [[!RFC5988]] using the
43364383
<code>http://www.w3.org/ns/json-ld#context</code> link relation
43374384
have been detected.</dd>
4385+
<dt><dfn>processing mode conflict</dfn></dt>
4386+
<dd>An attempt was made to change the <a>processing mode</a> which is
4387+
incompatible with the previous specified version.</dd>
43384388
<dt><dfn>recursive context inclusion</dfn></dt>
43394389
<dd>A cycle in remote context inclusions has been detected.</dd>
43404390
</dl>
@@ -4354,7 +4404,7 @@ <h3>Security Considerations</h3>
43544404
<h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
43554405
<ul>
43564406
<li>The <a href="#expansion-algorithm">Expansion Algorithm</a>
4357-
has a special processing mode, based on
4407+
has a special <a>processing mode</a>, based on
43584408
the <code>frame expansion</code> flag, to enable content associated with JSON-LD
43594409
frames, which may not otherwise be valid <a>JSON-LD documents</a>.</li>
43604410
<li>An <a>expanded term definition</a> can now have an
@@ -4381,7 +4431,6 @@ <h2>Open Issues</h2>
43814431
<p>The following is a list of open issues being worked on for the next release.</p>
43824432
<p class="issue" data-number="140"></p>
43834433
<p class="issue" data-number="195"></p>
4384-
<p class="issue" data-number="246"></p>
43854434
<p class="issue" data-number="269"></p>
43864435
<p class="issue" data-number="271"></p>
43874436
<p class="issue" data-number="272"></p>
@@ -4392,9 +4441,10 @@ <h2>Open Issues</h2>
43924441
<p class="issue" data-number="385"></p>
43934442
<p class="issue" data-number="398"></p>
43944443
<p class="issue" data-number="405"></p>
4395-
<p class="issue" data-number="415"></p>
43964444
<p class="issue" data-number="426"></p>
43974445
<p class="issue" data-number="446"></p>
4446+
<p class="issue" data-number="463"></p>
4447+
<p class="issue" data-number="461"></p>
43984448
</section>
43994449

44004450
<section class="appendix informative">

spec/latest/json-ld-framing/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ <h3>JsonLdProcessor</h3>
12271227
<a data-lt="JsonLdProcessor-frame-frame">frame</a> and
12281228
<a data-lt="JsonLdProcessor-frame-options">options</a> with
12291229
<code class="idlMemberName"><a data-cite="JSON-LD-API#dom-jsonldoptions-expandcontext">expandContext</a></code> set to <code>null</code>
1230-
and <code class="idlMemberName"><a data-cite="JSON-LD-API#dom-jsonldoptions-processingmode">processingMode</a></code> set to <strong>"json-ld-framing-1.1-expand-frame"</strong>.
1230+
and <code class="idlMemberName"><a data-cite="JSON-LD-API#dom-jsonldoptions-processingmode">processingMode</a></code> set to <strong>json-ld-1.1-expand-frame</strong>.
12311231
<li>Set <em>context</em> to the value of <code>@context</code>
12321232
from <a data-lt="JsonLdProcessor-frame-frame">frame</a>, if it exists, or to
12331233
a new empty <a>context</a>, otherwise.</li>
@@ -1443,6 +1443,12 @@ <h3>application/ld-frame+json</h3>
14431443

14441444
</section>
14451445

1446+
<section id="security" class="appendix">
1447+
<h3>Security Considerations</h3>
1448+
<p class="ednote">Consider requirements from <a href="https://w3ctag.github.io/security-questionnaire/">Self-Review Questionnaire: Security and Privacy</a>.</p>
1449+
<p>See, <a href="#iana-considerations" class="sectionRef"></a></p>
1450+
</section>
1451+
14461452
<section id="idl-index" class="appendix informative">
14471453
</section>
14481454

spec/latest/json-ld/index.html

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ <h2>Syntax Tokens and Keywords</h2>
397397
This keyword is described in <a class="sectionRef" href="#named-graphs"></a>.</dd>
398398
<dt class="changed"><code>@nest</code></dt><dd class="changed">Collects a set of <a>nested properties</a> within
399399
a <a>node object</a>.</dd>
400+
<dt class="changed"><code>@version</code></dt><dd class="changed">
401+
Used in a <a>context definition</a> to set the <a>processing mode</a>.
402+
New features since <a data-cite="JSON-LD-20140116">JSON-LD 1.0</a> [[!JSON-LD-20140116]] described in this specification are
403+
only available when <a>processing mode</a> has been explicitly set to
404+
<code>json-ld-1.1</code>.
405+
</dd>
400406
<dt><code>:</code></dt>
401407
<dd>The separator for JSON keys and values that use
402408
<a>compact IRIs</a>.</dd>
@@ -711,7 +717,7 @@ <h2>IRIs</h2>
711717
"@type": "@id"
712718
}
713719
...
714-
}****
720+
},****
715721
...
716722
"homepage": "http://manu.sporny.org/",
717723
...
@@ -829,7 +835,7 @@ <h2>Specifying the Type</h2>
829835
...
830836
****"Restaurant": "http://schema.org/Restaurant", ****
831837
****"Brewery": "http://schema.org/Brewery"****
832-
}
838+
},
833839
"@id": "http://example.org/places#BrewEats",
834840
****"@type": [ "Restaurant", "Brewery" ]****,
835841
...
@@ -858,6 +864,37 @@ <h1>Advanced Concepts</h1>
858864
the core functionality described above. The following section describes this
859865
advanced functionality in more detail.</p>
860866

867+
<section class="changed informative">
868+
<h2>JSON-LD 1.1 Processing Mode</h2>
869+
870+
<p>New features defined in JSON-LD 1.1 are available
871+
when the <a>processing mode</a> is set to <code>json-ld-1.1</code>.
872+
This may be set using the <code>@version</code> member in a <code>context</code>
873+
set to the value <code>1.1</code>, or through an API option.</p>
874+
875+
<pre class="example" data-transform="updateExample"
876+
title="Setting @version in context">
877+
<!--
878+
{
879+
"@context": {
880+
****"@version": 1.1****,
881+
...
882+
},
883+
...
884+
}
885+
-->
886+
</pre>
887+
888+
<p>The first <code>context</code> encountered when processing a
889+
document determines the <code>processing mode</code>,
890+
unless it is defined explicitly through an API option.</p>
891+
892+
<p class="note">Setting the <a>processing mode</a> explicitly
893+
for JSON-LD 1.1 is necessary so that a JSON-LD 1.0 processor
894+
does not attempt to process a JSON-LD 1.1 document and silently
895+
produce different results.</p>
896+
</section>
897+
861898
<section class="informative">
862899
<h2>Base IRI</h2>
863900

@@ -1481,7 +1518,7 @@ <h2>Advanced Context Usage</h2>
14811518
starting with an&nbsp;<code>@</code> character are to be avoided as they
14821519
might be used as <a>keyword</a> in future versions
14831520
of JSON-LD. Terms starting with an&nbsp;<code>@</code> character that are not
1484-
<a data-lt="keyword">JSON-LD 1.0 keywords</a> are treated as any other term, i.e.,
1521+
<a data-lt="keyword">JSON-LD 1.1 keywords</a> are treated as any other term, i.e.,
14851522
they are ignored unless mapped to an <a>IRI</a>. Furthermore, the use of
14861523
empty <a>terms</a> (<code>""</code>) is not allowed as
14871524
not all programming languages are able to handle empty JSON keys.</p>
@@ -2101,7 +2138,7 @@ <h2>Reverse Properties</h2>
21012138
-->
21022139
</pre>
21032140

2104-
<p class="changed">The <code>@reverse</code> <a>keyword</a> can also be used in
2141+
<p>The <code>@reverse</code> <a>keyword</a> can also be used in
21052142
<a>expanded term definitions</a>
21062143
to create reverse properties as shown in the following example:</p>
21072144

@@ -2238,6 +2275,9 @@ <h2>Scoped Contexts</h2>
22382275
</pre>
22392276

22402277
<p>Scoping on <code>@type</code> is useful when common properties are used to relate things of different types, where the vocabularies in use within different entities calls for different context scoping. For example, `hasPart`/`partOf` may be common terms used in a document, but mean different things depending on the context.</p>
2278+
2279+
<p class="note">Scoped Contexts are a new feature in JSON-LD 1.1, requiring
2280+
<a>processing mode</a> set to <code>json-ld-1.1</code></p>
22412281
</section>
22422282

22432283

@@ -2665,6 +2705,9 @@ <h2>Node Identifier Indexing</h2>
26652705
<p>The interpretation of the data above is exactly the same
26662706
as that in <a class="sectionRef" href="#data-indexing"></a>
26672707
using a JSON-LD processor.</p>
2708+
2709+
<p class="note"><a>Id maps</a> are a new feature in JSON-LD 1.1, requiring
2710+
<a>processing mode</a> set to <code>json-ld-1.1</code></p>
26682711
</section>
26692712

26702713
<section class="informative changed">
@@ -2712,6 +2755,9 @@ <h2>Node Type Indexing</h2>
27122755
been marked as an <a>type map</a>. The <code>schema:Corporpation</code> and
27132756
<code>schema:ProfessionalService</code> keys will be interpreted
27142757
as the <code>@type</code> property of the <a>node object</a> value.</p>
2758+
2759+
<p class="note"><a>Type maps</a> are a new feature in JSON-LD 1.1, requiring
2760+
<a>processing mode</a> set to <code>json-ld-1.1</code></p>
27152761
</section>
27162762

27172763
<section class="informative changed">
@@ -2791,6 +2837,9 @@ <h2>Nested Properties</h2>
27912837
}
27922838
-->
27932839
</pre>
2840+
2841+
<p class="note"><a>Nested properties</a> are a new feature in JSON-LD 1.1, requiring
2842+
<a>processing mode</a> set to <code>json-ld-1.1</code></p>
27942843
</section>
27952844

27962845
<section class="informative">
@@ -3467,6 +3516,9 @@ <h2>Context Definitions</h2>
34673516
its value MUST be a <a>absolute IRI</a>, a <a>compact IRI</a>,
34683517
a <a>blank node identifier</a>, a <a>term</a>, or <a>null</a>.</p>
34693518

3519+
<p class="changed">If the <a>context definition</a> has an <code>@version</code> key,
3520+
its value MUST be a <a>number</a> with the value <code>1.1</code>.</p>
3521+
34703522
<p>The value of keys that are not <a>keyword</a> MUST be either an
34713523
<a>absolute IRI</a>, a <a>compact IRI</a>, a <a>term</a>,
34723524
a <a>blank node identifier</a>, a <a>keyword</a>, <a>null</a>,
@@ -3728,7 +3780,6 @@ <h2>Changes since 1.0 Recommendation of 16 January 2014</h2>
37283780
<h4>Open Issues</h4>
37293781
<p>The following is a list of open issues being worked on for the next release.</p>
37303782
<p class="issue" data-number="195"></p>
3731-
<p class="issue" data-number="246"></p>
37323783
<p class="issue" data-number="269"></p>
37333784
<p class="issue" data-number="271"></p>
37343785
<p class="issue" data-number="272"></p>
@@ -3743,8 +3794,8 @@ <h4>Open Issues</h4>
37433794
<p class="issue" data-number="418"></p>
37443795
<p class="issue" data-number="426"></p>
37453796
<p class="issue" data-number="429"></p>
3746-
<p class="issue" data-number="430"></p>
37473797
<p class="issue" data-number="446"></p>
3798+
<p class="issue" data-number="463"></p>
37483799
</section>
37493800

37503801
<section class="appendix informative">

0 commit comments

Comments
 (0)