Skip to content

Commit

Permalink
fix: don't modify base when processing context inputs
Browse files Browse the repository at this point in the history
The the base URI passed to _prep_sources was being overwritten in anticipation of processing inner nestings, but this caused problems when processing multiple inputs. Changed the assignment to `base` to `new_base`.
  • Loading branch information
hsolbrig committed Dec 24, 2022
1 parent 36c35a8 commit d74c03a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rdflib/plugins/shared/jsonld/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def _prep_sources(
new_ctx = self._fetch_context(
source, source_doc_base, referenced_contexts
)
new_base = base
if new_ctx is None:
continue
else:
Expand All @@ -412,7 +413,7 @@ def _prep_sources(
# if base is not None, then source_doc_base won't be
# none due to how it is assigned.
assert source_doc_base is not None
base = urljoin(source_doc_base, source_url)
new_base = urljoin(source_doc_base, source_url)
source = new_ctx

if isinstance(source, dict):
Expand All @@ -422,7 +423,7 @@ def _prep_sources(

if isinstance(source, list):
self._prep_sources(
base, source, sources, referenced_contexts, source_url
new_base, source, sources, referenced_contexts, source_url
)
else:
sources.append((source_url, source))
Expand Down
2 changes: 2 additions & 0 deletions test/jsonld/local-suite/contexts/import1.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions test/jsonld/local-suite/contexts/import2.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
10 changes: 9 additions & 1 deletion test/jsonld/local-suite/manifest.jsonld
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@context": "http://json-ld.org/test-suite/context.jsonld",
"@context": "h2p://json-ld.org/test-suite/context.jsonld",
"@id": "",
"@type": "mf:Manifest",
"name": "RDFLib-jsonld local test suite",
Expand All @@ -19,6 +19,14 @@
"purpose": "Expanding urn IRIs recursively. Issue #75",
"input": "sample-urn-in.jsonld",
"expect": "sample-urn-out.nq"
},
{
"@id": "#toRdf-twoimports",
"@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
"name": "JSON-LD parser doesn't restore root directory",
"purpose": "Multiple @id aliases. Issue #2164",
"input": "toRdf-twoimports-in.jsonld",
"expect": "toRdf-twoimports-out.nq"
}
]
}
6 changes: 6 additions & 0 deletions test/jsonld/local-suite/toRdf-twoimports-in.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": [
"contexts/import1.jsonld",
"contexts/import2.jsonld"
]
}
Empty file.
7 changes: 6 additions & 1 deletion test/jsonld/test_localsuite.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import json
from os import chdir, getcwd
from os import path as p
from pathlib import Path

import pytest

from rdflib.term import URIRef

from . import runner

TC_BASE = "https://rdflib.github.io/rdflib-jsonld/local-testsuite/"
# TODO FIXME: We should be using this URI instead of a file URI, but as there is
# no way to customize URI loading yet this will not work, so instead TC_BASE is
# set to a file-uri further down.
# TC_BASE = "https://rdflib.github.io/rdflib-jsonld/local-testsuite/"

TC_BASE = (Path(__file__).parent / "local-suite").absolute().as_uri() + "/"

testsuite_dir = p.join(p.abspath(p.dirname(__file__)), "local-suite")

Expand Down

0 comments on commit d74c03a

Please sign in to comment.