Skip to content

Commit f0ee867

Browse files
gkelloggdavidlehn
authored andcommitted
Skip things that look like keywords.
1 parent 02bd0a1 commit f0ee867

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

lib/context.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ api.createTermDefinition = ({
397397
'Invalid JSON-LD syntax; keywords cannot be overridden.',
398398
'jsonld.SyntaxError',
399399
{code: 'keyword redefinition', context: localCtx, term});
400+
} else if(term.match(/@[a-zA-Z]+$/)) {
401+
// FIXME: remove logging and use a handler
402+
console.warn('WARNING: terms beginning with "@" are reserved' +
403+
' for future use and ignored', {term});
404+
return;
400405
} else if(term === '') {
401406
throw new JsonLdError(
402407
'Invalid JSON-LD syntax; a term cannot be an empty string.',
@@ -484,6 +489,15 @@ api.createTermDefinition = ({
484489
'absolute IRI or a blank node identifier.',
485490
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
486491
}
492+
493+
if(reverse.match(/@[a-zA-Z]+$/)) {
494+
// FIXME: remove logging and use a handler
495+
console.warn('WARNING: values beginning with "@" are reserved' +
496+
' for future use and ignored', {reverse});
497+
activeCtx.mappings.delete(term);
498+
return;
499+
}
500+
487501
mapping['@id'] = id;
488502
mapping.reverse = true;
489503
} else if('@id' in value) {
@@ -497,6 +511,12 @@ api.createTermDefinition = ({
497511
if(id === null) {
498512
// reserve a null term, which may be protected
499513
mapping['@id'] = null;
514+
} else if(!api.isKeyword(id) && id.match(/@[a-zA-Z]+$/)) {
515+
// FIXME: remove logging and use a handler
516+
console.warn('WARNING: values beginning with "@" are reserved' +
517+
' for future use and ignored', {id});
518+
activeCtx.mappings.delete(term);
519+
return;
500520
} else if(id !== term) {
501521
// expand and add @id mapping
502522
id = _expandIri(
@@ -850,6 +870,11 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
850870
return value;
851871
}
852872

873+
// ignore non-keyword things that look like a keyword
874+
if(value.match(/^@[a-zA-Z]+$/)) {
875+
return null;
876+
}
877+
853878
// define term dependency if not defined
854879
if(localCtx && localCtx.hasOwnProperty(value) &&
855880
defined.get(value) !== true) {

lib/expand.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,6 @@ async function _expandObject({
660660
continue;
661661
}
662662

663-
// skip unknown keywords
664-
//if(expandedProperty.startsWith('@')) {
665-
// continue;
666-
//}
667-
668663
// use potential scoped context for key
669664
let termCtx = activeCtx;
670665
const ctx = _getContextValue(activeCtx, key, '@context');

tests/test-common.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ const TEST_TYPES = {
6363
specVersion: ['json-ld-1.0'],
6464
// FIXME
6565
idRegex: [
66-
// terms having form of keyword
67-
/expand-manifest.jsonld#t0119$/,
68-
/expand-manifest.jsonld#t0120$/,
69-
/expand-manifest.jsonld#t0122$/,
7066
// html
7167
/html-manifest.jsonld#te001$/,
7268
/html-manifest.jsonld#te002$/,
@@ -100,15 +96,8 @@ const TEST_TYPES = {
10096
// colliding keywords
10197
/expand-manifest.jsonld#t0114$/,
10298
// keywords
103-
/expand-manifest.jsonld#tpr30$/,
104-
/expand-manifest.jsonld#tpr31$/,
10599
/expand-manifest.jsonld#tpr32$/,
106100
/expand-manifest.jsonld#tpr33$/,
107-
/expand-manifest.jsonld#tpr34$/,
108-
/expand-manifest.jsonld#tpr35$/,
109-
/expand-manifest.jsonld#tpr36$/,
110-
/expand-manifest.jsonld#tpr37$/,
111-
/expand-manifest.jsonld#tpr39$/,
112101
// direction
113102
/expand-manifest.jsonld#tdi01$/,
114103
/expand-manifest.jsonld#tdi02$/,
@@ -275,10 +264,6 @@ const TEST_TYPES = {
275264
specVersion: ['json-ld-1.0'],
276265
// FIXME
277266
idRegex: [
278-
// terms having form of keyword
279-
/toRdf-manifest.jsonld#te119$/,
280-
/toRdf-manifest.jsonld#te120$/,
281-
/toRdf-manifest.jsonld#te122$/,
282267
// well formed
283268
/toRdf-manifest.jsonld#twf05$/,
284269
// html
@@ -309,15 +294,9 @@ const TEST_TYPES = {
309294
// colliding keyword
310295
/toRdf-manifest.jsonld#te114$/,
311296
// keywords
312-
/toRdf-manifest.jsonld#tpr30$/,
313297
/toRdf-manifest.jsonld#tpr31$/,
314298
/toRdf-manifest.jsonld#tpr32$/,
315299
/toRdf-manifest.jsonld#tpr33$/,
316-
/toRdf-manifest.jsonld#tpr34$/,
317-
/toRdf-manifest.jsonld#tpr35$/,
318-
/toRdf-manifest.jsonld#tpr36$/,
319-
/toRdf-manifest.jsonld#tpr37$/,
320-
/toRdf-manifest.jsonld#tpr39$/,
321300
// direction
322301
/toRdf-manifest.jsonld#tdi01$/,
323302
/toRdf-manifest.jsonld#tdi02$/,

0 commit comments

Comments
 (0)