Skip to content

@context resolution respects relative URLs. #337

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

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,12 +1174,12 @@ async function _retrieveContextUrls(input, options) {
const {documentLoader} = options;

// retrieve all @context URLs in input
await retrieve(input, new Set(), documentLoader);
await retrieve(input, new Set(), documentLoader, options.base);

return input;

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

// find all URLs in the given document
const urls = new Map();
_findContextUrls(doc, urls, false, options.base);
_findContextUrls(doc, urls, false, baseUrl);
if(urls.size === 0) {
return;
}
Expand Down Expand Up @@ -1256,13 +1256,13 @@ async function _retrieveContextUrls(input, options) {
}

// recurse
await retrieve(ctx, _cycles, documentLoader);
await retrieve(ctx, _cycles, documentLoader, url);

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

// replace all @context URLs in the document
_findContextUrls(doc, urls, true, options.base);
_findContextUrls(doc, urls, true, baseUrl);
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/documentLoaders/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = ({
const statusText = http.STATUS_CODES[res.statusCode];
if(res.statusCode >= 400) {
throw new JsonLdError(
'URL could not be dereferenced: ' + statusText,
`URL "${url}" could not be dereferenced: ${statusText}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change from our usual style. URL is already a param in the details so could be omitted in the message text. Could also move the statusText to details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge PR, but may change this text later.

'jsonld.InvalidUrl', {
code: 'loading document failed',
url,
Expand Down