Skip to content

Commit

Permalink
Skip things that look like keywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg authored and davidlehn committed Jan 29, 2020
1 parent 02bd0a1 commit f0ee867
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
25 changes: 25 additions & 0 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ api.createTermDefinition = ({
'Invalid JSON-LD syntax; keywords cannot be overridden.',
'jsonld.SyntaxError',
{code: 'keyword redefinition', context: localCtx, term});
} else if(term.match(/@[a-zA-Z]+$/)) {
// FIXME: remove logging and use a handler
console.warn('WARNING: terms beginning with "@" are reserved' +
' for future use and ignored', {term});
return;
} else if(term === '') {
throw new JsonLdError(
'Invalid JSON-LD syntax; a term cannot be an empty string.',
Expand Down Expand Up @@ -484,6 +489,15 @@ api.createTermDefinition = ({
'absolute IRI or a blank node identifier.',
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
}

if(reverse.match(/@[a-zA-Z]+$/)) {
// FIXME: remove logging and use a handler
console.warn('WARNING: values beginning with "@" are reserved' +
' for future use and ignored', {reverse});
activeCtx.mappings.delete(term);
return;
}

mapping['@id'] = id;
mapping.reverse = true;
} else if('@id' in value) {
Expand All @@ -497,6 +511,12 @@ api.createTermDefinition = ({
if(id === null) {
// reserve a null term, which may be protected
mapping['@id'] = null;
} else if(!api.isKeyword(id) && id.match(/@[a-zA-Z]+$/)) {
// FIXME: remove logging and use a handler
console.warn('WARNING: values beginning with "@" are reserved' +
' for future use and ignored', {id});
activeCtx.mappings.delete(term);
return;
} else if(id !== term) {
// expand and add @id mapping
id = _expandIri(
Expand Down Expand Up @@ -850,6 +870,11 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
return value;
}

// ignore non-keyword things that look like a keyword
if(value.match(/^@[a-zA-Z]+$/)) {
return null;
}

// define term dependency if not defined
if(localCtx && localCtx.hasOwnProperty(value) &&
defined.get(value) !== true) {
Expand Down
5 changes: 0 additions & 5 deletions lib/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,6 @@ async function _expandObject({
continue;
}

// skip unknown keywords
//if(expandedProperty.startsWith('@')) {
// continue;
//}

// use potential scoped context for key
let termCtx = activeCtx;
const ctx = _getContextValue(activeCtx, key, '@context');
Expand Down
21 changes: 0 additions & 21 deletions tests/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ const TEST_TYPES = {
specVersion: ['json-ld-1.0'],
// FIXME
idRegex: [
// terms having form of keyword
/expand-manifest.jsonld#t0119$/,
/expand-manifest.jsonld#t0120$/,
/expand-manifest.jsonld#t0122$/,
// html
/html-manifest.jsonld#te001$/,
/html-manifest.jsonld#te002$/,
Expand Down Expand Up @@ -100,15 +96,8 @@ const TEST_TYPES = {
// colliding keywords
/expand-manifest.jsonld#t0114$/,
// keywords
/expand-manifest.jsonld#tpr30$/,
/expand-manifest.jsonld#tpr31$/,
/expand-manifest.jsonld#tpr32$/,
/expand-manifest.jsonld#tpr33$/,
/expand-manifest.jsonld#tpr34$/,
/expand-manifest.jsonld#tpr35$/,
/expand-manifest.jsonld#tpr36$/,
/expand-manifest.jsonld#tpr37$/,
/expand-manifest.jsonld#tpr39$/,
// direction
/expand-manifest.jsonld#tdi01$/,
/expand-manifest.jsonld#tdi02$/,
Expand Down Expand Up @@ -275,10 +264,6 @@ const TEST_TYPES = {
specVersion: ['json-ld-1.0'],
// FIXME
idRegex: [
// terms having form of keyword
/toRdf-manifest.jsonld#te119$/,
/toRdf-manifest.jsonld#te120$/,
/toRdf-manifest.jsonld#te122$/,
// well formed
/toRdf-manifest.jsonld#twf05$/,
// html
Expand Down Expand Up @@ -309,15 +294,9 @@ const TEST_TYPES = {
// colliding keyword
/toRdf-manifest.jsonld#te114$/,
// keywords
/toRdf-manifest.jsonld#tpr30$/,
/toRdf-manifest.jsonld#tpr31$/,
/toRdf-manifest.jsonld#tpr32$/,
/toRdf-manifest.jsonld#tpr33$/,
/toRdf-manifest.jsonld#tpr34$/,
/toRdf-manifest.jsonld#tpr35$/,
/toRdf-manifest.jsonld#tpr36$/,
/toRdf-manifest.jsonld#tpr37$/,
/toRdf-manifest.jsonld#tpr39$/,
// direction
/toRdf-manifest.jsonld#tdi01$/,
/toRdf-manifest.jsonld#tdi02$/,
Expand Down

0 comments on commit f0ee867

Please sign in to comment.