-
Notifications
You must be signed in to change notification settings - Fork 203
IRI fixes #333
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
IRI fixes #333
Changes from 7 commits
4725fe2
130069d
d83d7ef
3cfae0b
223d7d7
a812777
3d18f9d
804f0a7
c5ab700
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ api.process = async ({ | |
|
||
// if not set explicitly, set processingMode to "json-ld-1.1" | ||
rval.processingMode = | ||
rval.processingMode || activeCtx.processingMode || 'json-ld-1.1'; | ||
rval.processingMode || activeCtx.processingMode; | ||
|
||
// handle @base | ||
if('@base' in ctx) { | ||
|
@@ -205,7 +205,7 @@ api.process = async ({ | |
} else if(_isAbsoluteIri(base)) { | ||
base = parseUrl(base); | ||
} else if(_isRelativeIri(base)) { | ||
base = parseUrl(prependBase(activeCtx['@base'].href, base)); | ||
base = parseUrl(prependBase(rval['@base'].href, base)); | ||
} else { | ||
throw new JsonLdError( | ||
'Invalid JSON-LD syntax; the value of "@base" in a ' + | ||
|
@@ -227,13 +227,14 @@ api.process = async ({ | |
'Invalid JSON-LD syntax; the value of "@vocab" in a ' + | ||
'@context must be a string or null.', | ||
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx}); | ||
} else if(!_isAbsoluteIri(value)) { | ||
} else if(!_isAbsoluteIri(value) && api.processingMode(rval, 1.0)) { | ||
throw new JsonLdError( | ||
'Invalid JSON-LD syntax; the value of "@vocab" in a ' + | ||
'@context must be an absolute IRI.', | ||
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx}); | ||
} else { | ||
rval['@vocab'] = value; | ||
rval['@vocab'] = _expandIri(rval, value, {vocab: true, base: true}, | ||
undefined, undefined, options); | ||
} | ||
defined.set('@vocab', true); | ||
} | ||
|
@@ -389,7 +390,7 @@ api.createTermDefinition = ( | |
// always compute whether term has a colon as an optimization for | ||
// _compactIri | ||
const colon = term.indexOf(':'); | ||
mapping._termHasColon = (colon !== -1); | ||
mapping._termHasColon = (colon > 0); | ||
|
||
if('@reverse' in value) { | ||
if('@id' in value) { | ||
|
@@ -444,9 +445,9 @@ api.createTermDefinition = ( | |
} | ||
mapping['@id'] = id; | ||
// indicate if this term may be used as a compact IRI prefix | ||
mapping._prefix = (!mapping._termHasColon && | ||
id.match(/[:\/\?#\[\]@]$/) && | ||
(simpleTerm || api.processingMode(activeCtx, 1.0))); | ||
mapping._prefix = (simpleTerm && | ||
!mapping._termHasColon && | ||
id.match(/[:\/\?#\[\]@]$/)); | ||
} | ||
} | ||
|
||
|
@@ -753,7 +754,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) { | |
|
||
// split value into prefix:suffix | ||
const colon = value.indexOf(':'); | ||
if(colon !== -1) { | ||
if(colon > 0) { | ||
const prefix = value.substr(0, colon); | ||
const suffix = value.substr(colon + 1); | ||
|
||
|
@@ -769,13 +770,15 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) { | |
} | ||
|
||
// use mapping if prefix is defined | ||
if(activeCtx.mappings.has(prefix)) { | ||
const mapping = activeCtx.mappings.get(prefix); | ||
const mapping = activeCtx.mappings.get(prefix); | ||
if(mapping && mapping._prefix) { | ||
return mapping['@id'] + suffix; | ||
} | ||
|
||
// already absolute IRI | ||
return value; | ||
if(_isAbsoluteIri(value)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this extra check needed now? It still appears to be within the positive check for a colon in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a colon isn’t sufficient to make it an absolute (or compact) IRI. This final test ensure that only an absolute IRI will be returned, otherwise, if falls through. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
return value; | ||
} | ||
} | ||
|
||
// prepend vocab | ||
|
@@ -1086,11 +1089,10 @@ api.getAllContexts = async (input, options) => { | |
*/ | ||
api.processingMode = (activeCtx, version) => { | ||
if(version.toString() >= '1.1') { | ||
return activeCtx.processingMode && | ||
return !activeCtx.processingMode || | ||
activeCtx.processingMode >= 'json-ld-' + version.toString(); | ||
} else { | ||
return !activeCtx.processingMode || | ||
activeCtx.processingMode === 'json-ld-1.0'; | ||
return activeCtx.processingMode === 'json-ld-1.0'; | ||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ api.prependBase = (base, iri) => { | |
return iri; | ||
} | ||
// already an absolute IRI | ||
if(iri.indexOf(':') !== -1) { | ||
if(api.isAbsolute(iri)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidlehn -- it would be good to understand the performance impact on things like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have benchmarking code. I'm not sure what the tests would be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While a regex comparison is more compute intensive than an indexOf, they should be pretty similar. In any case, it's incorrect to just look for a ':' as a test for if an IRI is absolute. |
||
return iri; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.