Skip to content

Commit 1691fb9

Browse files
Eric Prud'hommeauxdavidlehn
Eric Prud'hommeaux
authored andcommitted
@context resolution respects relative URLs.
c.f. w3c/json-ld-api#228
1 parent 6a24620 commit 1691fb9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/context.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,12 +1187,12 @@ async function _retrieveContextUrls(input, options) {
11871187
const {documentLoader} = options;
11881188

11891189
// retrieve all @context URLs in input
1190-
await retrieve(input, new Set(), documentLoader);
1190+
await retrieve(input, new Set(), documentLoader, options.base);
11911191

11921192
return input;
11931193

11941194
// recursive function that will retrieve all @context URLs in documents
1195-
async function retrieve(doc, cycles, documentLoader) {
1195+
async function retrieve(doc, cycles, documentLoader, baseUrl) {
11961196
if(cycles.size > MAX_CONTEXT_URLS) {
11971197
throw new JsonLdError(
11981198
'Maximum number of @context URLs exceeded.',
@@ -1202,7 +1202,7 @@ async function _retrieveContextUrls(input, options) {
12021202

12031203
// find all URLs in the given document
12041204
const urls = new Map();
1205-
_findContextUrls(doc, urls, false, options.base);
1205+
_findContextUrls(doc, urls, false, baseUrl);
12061206
if(urls.size === 0) {
12071207
return;
12081208
}
@@ -1269,13 +1269,13 @@ async function _retrieveContextUrls(input, options) {
12691269
}
12701270

12711271
// recurse
1272-
await retrieve(ctx, _cycles, documentLoader);
1272+
await retrieve(ctx, _cycles, documentLoader, url);
12731273

12741274
// store retrieved context w/replaced @context URLs
12751275
urls.set(url, ctx['@context']);
12761276

12771277
// replace all @context URLs in the document
1278-
_findContextUrls(doc, urls, true, options.base);
1278+
_findContextUrls(doc, urls, true, baseUrl);
12791279
}));
12801280
}
12811281
}

lib/documentLoaders/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = ({
8383
const statusText = http.STATUS_CODES[res.statusCode];
8484
if(res.statusCode >= 400) {
8585
throw new JsonLdError(
86-
'URL could not be dereferenced: ' + statusText,
86+
'URL ' + url + ' could not be dereferenced: ' + statusText,
8787
'jsonld.InvalidUrl', {
8888
code: 'loading document failed',
8989
url,

0 commit comments

Comments
 (0)