Update to latest jsonld.js.
--- a/playground/jsonld.js Thu Feb 28 15:08:56 2013 +0100
+++ b/playground/jsonld.js Thu Feb 28 16:02:43 2013 -0500
@@ -2436,6 +2436,34 @@
// define context mappings for keys in local context
var defined = {};
+ // handle @base
+ if('@base' in ctx) {
+ var base = ctx['@base'];
+
+ // reset base
+ if(base === null) {
+ base = options.base;
+ }
+ else if(!_isString(base)) {
+ throw new JsonLdError(
+ 'Invalid JSON-LD syntax; the value of "@base" in a ' +
+ '@context must be a string or null.',
+ 'jsonld.SyntaxError', {context: ctx});
+ }
+ else if(!_isAbsoluteIri(base)) {
+ throw new JsonLdError(
+ 'Invalid JSON-LD syntax; the value of "@base" in a ' +
+ '@context must be an absolute IRI.',
+ 'jsonld.SyntaxError', {context: ctx});
+ }
+ else {
+ base = jsonld.url.parse(base || '');
+ base.pathname = base.pathname || '';
+ rval['@base'] = base;
+ }
+ defined['@base'] = true;
+ }
+
// handle @vocab
if('@vocab' in ctx) {
var value = ctx['@vocab'];
@@ -4321,9 +4349,9 @@
* @return the expanded value.
*/
function _expandIri(activeCtx, value, relativeTo, localCtx, defined) {
- // nothing to expand
- if(value === null) {
- return null;
+ // already expanded
+ if(value === null || _isKeyword(value)) {
+ return value;
}
// define term dependency if not defined
@@ -4537,9 +4565,12 @@
return iri;
}
+ // remove root from IRI and parse remainder
+ var rel = jsonld.url.parse(iri.substr(root.length));
+
// remove path segments that match
var baseSegments = base.pathname.split('/');
- var iriSegments = iri.substr(root.length).split('/');
+ var iriSegments = rel.pathname.split('/');
while(baseSegments.length > 0 && iriSegments.length > 0) {
if(baseSegments[0] !== iriSegments[0]) {
break;
@@ -4563,6 +4594,18 @@
// prepend remaining segments
rval += iriSegments.join('/');
+ // add query and hash
+ if(rel.query) {
+ rval += '?' + rel.query;
+ }
+ if(rel.hash) {
+ rval += rel.hash;
+ }
+
+ if(rval === '') {
+ rval = './';
+ }
+
return rval;
}