Skip to content

Protected term errors #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 51 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,14 @@ <h3>Algorithm</h3>

<p>This algorithm specifies how a new <a>active context</a> is updated
with a <a>local context</a>. The algorithm takes two required
<span class="changed">and one optional</span>
<span class="changed">and two optional</span>
input variables.
The required inputs inputs are an <var>active context</var> and a <var>local context</var>.
The optional input is an <a>array</a> <var>remote contexts</var>,
defaulting to a new empty <a>array</a>, which is used to detect cyclical context inclusions.</p>
The required inputs are an <var>active context</var> and a <var>local context</var>.
The optional inputs are an <a>array</a> <var>remote contexts</var>,
defaulting to a new empty <a>array</a>, which is used to detect cyclical context inclusions.
<span class="changed">and <var>from term</var>, defaulting to <code>false</code>,
which is used to allow changes to protected terms.</span>.
</p>

<ol>
<li>Initialize <var>result</var> to the result of cloning
Expand All @@ -1026,12 +1029,20 @@ <h3>Algorithm</h3>
<li>
For each item <var>context</var> in <var>local context</var>:
<ol>
<li>If <var>context</var> is <code>null</code>, set <var>result</var> to a
newly-initialized <var>active context</var> and continue with the
next <var>context</var>.
<span class="note">In JSON-LD 1.0, the <a>base IRI</a> was given
a default value here; this is now described conditionally
in <a href="#the-application-programming-interface" class="sectionRef"></a>.</span></li>
<li>If <var>context</var> is <code>null</code>:
<ol>
<li class="changed">If <var>from term</var> is <code>false</code> and <var>active context</var>
contains any <a>protected</a> <a>term definitions</a>,
an <a data-link-for="JsonLdErrorCode">invalid context nullification</a>
has been detected and processing is aborted.</li>
<li>Otherwise, set <var>result</var> to a
newly-initialized <var>active context</var> and continue with the
next <var>context</var>.
<span class="note">In JSON-LD 1.0, the <a>base IRI</a> was given
a default value here; this is now described conditionally
in <a href="#the-application-programming-interface" class="sectionRef"></a>.</span></li>
</ol>
</li>
<li>If <var>context</var> is a <a>string</a>,
<ol>
<li>Set <var>context</var> to the result of resolving <var>value</var> against
Expand Down Expand Up @@ -1153,8 +1164,9 @@ <h3>Algorithm</h3>
passing <var>result</var> for <var>active context</var>,
<var>context</var> for <var>local context</var>, <var>key</var>,
<var>defined</var>,
<span class="changed">and the value of the <code>@protected</code>
member from <var>context</var>, if any, for <var>protected</var></span>.</li>
<span class="changed">the value of the <code>@protected</code>
member from <var>context</var>, if any, for <var>protected</var></span>,
and <var>from term</var>.</li>
</ol>
</li>
<li>Return <var>result</var>.</li>
Expand Down Expand Up @@ -1199,12 +1211,15 @@ <h3>Overview</h3>
<section class="algorithm">
<h3>Algorithm</h3>

<p>The algorithm has four required <span class="changed">and one optional</span> inputs.
<p>The algorithm has four required <span class="changed">and two optional</span> inputs.
The required inputs are
an <var>active context</var>, a <var>local context</var>,
a <var>term</var>, and a map <var>defined</var>.
<span class="changed">The optional input is
<var>protected</var> which defaults to <code>false</code>.</span></p>
<span class="changed">The optional inputs are
<var>protected</var> which defaults to <code>false</code>,
and <var>from term</var>, defaulting to <code>false</code>,
which is used to allow changes to protected terms.</span>.
</p>
<ol>
<li>If <var>defined</var> contains the <a>member</a> <var>term</var> and the associated
value is <code>true</code> (indicating that the
Expand All @@ -1228,9 +1243,11 @@ <h3>Algorithm</h3>
<var>term</var> MUST NOT be a <a>keyword</a> and a
<a data-link-for="JsonLdErrorCode">keyword redefinition</a>
error has been detected and processing is aborted.</li>
<li class="changed">If the <var>active context</var> has an existing
<a>term definition</a> for <var>term</var> which is protected, processing is aborted;
processors SHOULD issue a warning that an attempt was made to redefine a protected term.</li>
<li class="changed">If <var>from term</var> is <code>false</code>
and <var>active context</var> has an existing
<a>term definition</a> for <var>term</var> which is protected,
a <a data-link-for="JsonLdErrorCode">protected term redefinition</a> error has been detected,
and processing is aborted.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one thing we might want to modify here is to allow for "redefinitions" that cause the exact same term definition to occur. There's really no reason disallow that from an authorship perspective -- and people might be surprised that they can't combine two contexts that share a common base context with protected terms. On the other hand, this would complicate implementation.

@davidlehn -- since you were in the code most recently, would this be a tough thing to support?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, I don't think that this should hold up the PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could say that an attempt to redefine a term definition that is exactly equivalent to the existing definition is allowed, needing to define what we mean by equivalent, but it seems an unnecessary complication to me.

<li>Otherwise, remove any existing <a>term definition</a> for <var>term</var> in
<var>active context</var>.</li>
<li>If <var>value</var> is <code>null</code> or <var>value</var>
Expand Down Expand Up @@ -1412,7 +1429,8 @@ <h3>Algorithm</h3>
<li>Initialize <var>context</var> to the value associated with the
<code>@context</code> <a>member</a>, which is treated as a <var>local context</var>.</li>
<li>Invoke the <a href="#context-processing-algorithm">Context Processing algorithm</a>
using the <var>active context</var> and <var>context</var> as <var>local context</var>.
using the <var>active context</var>, <var>context</var> as <var>local context</var>,
and <code>true</code> for <var>from term</var>.
If any error is detected, an
<a data-link-for="JsonLdErrorCode">invalid scoped context</a> error
has been detected and processing is aborted.</li>
Expand Down Expand Up @@ -1514,7 +1532,7 @@ <h3>Overview</h3>
<a href="#create-term-definition">Create Term Definition algorithm</a>.</p>
</section>

<section>
<section class="algorithm">
<h3>Algorithm</h3>

<p>The algorithm takes two required and four optional input variables. The
Expand Down Expand Up @@ -1938,8 +1956,9 @@ <h3>Algorithm</h3>
<li class="changed">If <var>key</var>'s <a>term definition</a> in <var>active context</var>
has a <a>local context</a>, set <var>term context</var> to the result of the
<a href="#context-processing-algorithm">Context Processing algorithm</a>,
passing <var>active context</var> and the value of the
<var>key</var>'s <a>local context</a> as <var>local context</var>. Otherwise,
passing <var>active context</var>, the value of the
<var>key</var>'s <a>local context</a> as <var>local context</var>,
and <code>true</code> for <var>from term</var>. Otherwise,
set <var>term context</var> to <var>active context</var>.</li>
<li>Set <var>container mapping</var> to <var>key</var>'s <a>container mapping</a> in
<var class="changed">term context</var>.</li>
Expand Down Expand Up @@ -2384,8 +2403,9 @@ <h3>Algorithm</h3>
<ol>
<li>Set <var>active context</var> to the result of the
<a href="#context-processing-algorithm">Context Processing algorithm</a>,
passing <var>active context</var> and the value of the
<var>active property</var>'s <a>local context</a> as <var>local context</var>.</li>
passing <var>active context</var>, the value of the
<var>active property</var>'s <a>local context</a> as <var>local context</var>,
<span class="changed">and <code>true</code> for <var>from term</var></span>.</li>
<li>Set <var>inverse context</var> using the
<a href="#inverse-context-creation">Inverse Context Creation algorithm</a>
using <var>active context</var>.</li>
Expand Down Expand Up @@ -5626,6 +5646,7 @@ <h4>JsonLdErrorCode</h4>
"invalid @version value",
"invalid base IRI",
"invalid container mapping",
"invalid context nullification",
"invalid default language",
"invalid IRI mapping",
"invalid keyword alias",
Expand Down Expand Up @@ -5653,6 +5674,7 @@ <h4>JsonLdErrorCode</h4>
"loading remote context failed",
"multiple context link headers",
"processing mode conflict",
"protected term redefinition",
"context overflow"
};
--></pre>
Expand Down Expand Up @@ -5769,6 +5791,11 @@ <h4>JsonLdErrorCode</h4>
which is incompatible with the previous specified version.</dd>
<dt><dfn>context overflow</dfn></dt>
<dd>maximum number of <code>@context</code> URLs exceeded.</dd>
<dt class="changed"><dfn>invalid context nullification</dfn></dt>
<dd class="changed">An attempt was made to nullify a context
containing <a>protected</a> <a>term definitions</a>.</dd>
<dt class="changed"><dfn>protected term redefinition</dfn></dt>
<dd class="changed">An attempt was made to redefine a <a>protected</a> term.</dd>
</dl>
</section>
</section> <!-- end of Error Handling -->
Expand Down
36 changes: 36 additions & 0 deletions tests/compact-manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,42 @@
"input": "compact/pi06-in.jsonld",
"context": "compact/pi06-context.jsonld",
"expect": "compact/pi06-out.jsonld"
}, {
"@id": "#tpr01",
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
"name": "Check illegal clearing of context with protected terms",
"purpose": "Check error when clearing a context with protected terms.",
"option": {"specVersion": "json-ld-1.1"},
"input": "compact/pr01-in.jsonld",
"context": "compact/pr01-context.jsonld",
"expect": "invalid context nullification"
}, {
"@id": "#tpr02",
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
"name": "Check illegal overriding of protected term",
"purpose": "Check error when overriding a protected term.",
"option": {"specVersion": "json-ld-1.1"},
"input": "compact/pr02-in.jsonld",
"context": "compact/pr02-context.jsonld",
"expect": "protected term redefinition"
}, {
"@id": "#tpr03",
"@type": ["jld:NegativeEvaluationTest", "jld:CompactTest"],
"name": "Check illegal overriding of protected term from type-scoped context",
"purpose": "Check error when overriding a protected term from type-scoped context.",
"option": {"specVersion": "json-ld-1.1"},
"input": "compact/pr02-in.jsonld",
"context": "compact/pr02-context.jsonld",
"expect": "protected term redefinition"
}, {
"@id": "#tpr04",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
"name": "Check legal overriding of protected term from property-scoped context",
"purpose": "Check overriding a protected term from property-scoped context.",
"option": {"specVersion": "json-ld-1.1"},
"input": "compact/pr04-in.jsonld",
"context": "compact/pr04-context.jsonld",
"expect": "compact/pr04-out.jsonld"
}, {
"@id": "#tr001",
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
Expand Down
7 changes: 7 additions & 0 deletions tests/compact/pr01-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": [{
"@vocab": "http://example.com/",
"@version": 1.1,
"protected": {"@protected": true}
}, null]
}
3 changes: 3 additions & 0 deletions tests/compact/pr01-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[{
"http://example/a": [{"@id": "http://example.org/foo"}]
}]
9 changes: 9 additions & 0 deletions tests/compact/pr02-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"@context": [{
"@vocab": "http://example.com/",
"@version": 1.1,
"protected": {"@protected": true}
}, {
"protected": "http://example.com/protected"
}]
}
3 changes: 3 additions & 0 deletions tests/compact/pr02-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[{
"http://example/a": [{"@id": "http://example.org/foo"}]
}]
8 changes: 8 additions & 0 deletions tests/compact/pr03-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.com/",
"protected": {"@protected": true},
"Type": {"@context": {"protected": {"@type": "@id"},}}
}
}
7 changes: 7 additions & 0 deletions tests/compact/pr03-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[{
"http://example.com/protected": [{"@value": "p === http://example.com/protected"}],
"http://example.com/unprotected": [{
"@type": "http://example.com/Type",
"http://example.com/protected": [{"@value": "p === http://example.com/protected"}]
}]
}]
8 changes: 8 additions & 0 deletions tests/compact/pr04-context.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.com/",
"protected": {"@protected": true},
"unprotected": {"@context": {"protected": {"@language": "en"}}}
}
}
9 changes: 9 additions & 0 deletions tests/compact/pr04-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[{
"http://example.com/protected": [{"@value": "p === http://example.com/protected"}],
"http://example.com/unprotected": [{
"http://example.com/protected": [{
"@value": "p === http://example.com/protected",
"@language": "en"
}]
}]
}]
14 changes: 14 additions & 0 deletions tests/compact/pr04-out.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@context": {
"@version": 1.1,
"@vocab": "http://example.com/",
"protected": {"@protected": true},
"unprotected": {
"@context": {"protected": {"@language": "en"}}
}
},
"protected": "p === http://example.com/protected",
"unprotected": {
"protected": "p === http://example.com/protected"
}
}
Loading