Skip to content

Commit 45c2942

Browse files
committed
Ignore @base if remote context is not relative
If the remote context is not relative and seems to be a http URI don't prefix the base IRI to it. The remote context is not validated nor tested if it's resolvable. It's just tested if it's not a relative URI - which is totally possible and would, in conjunction with a base IRI, made into valid remote context. See #304.
1 parent b856235 commit 45c2942

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

core/src/main/java/com/github/jsonldjava/core/Context.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ private Context parse(Object localContext, List<String> remoteContexts,
187187
}
188188
// 3.2)
189189
else if (context instanceof String) {
190-
String uri = (String) result.get(JsonLdConsts.BASE);
190+
String uri = null;
191+
// @base is ignored when processing remote contexts, https://github.com/jsonld-java/jsonld-java/issues/304
192+
if (!context.toString().matches("^[hH][tT][tT][pP][sS]?://.*")) {
193+
uri = (String) result.get(JsonLdConsts.BASE);
194+
}
191195
uri = JsonLdUrl.resolve(uri, (String) context);
192196
// 3.2.2
193197
if (remoteContexts.contains(uri)) {

core/src/test/java/com/github/jsonldjava/core/DocumentLoaderTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,19 @@ public void testDisallowRemoteContexts() throws Exception {
381381
}
382382

383383
@Test
384-
public void injectContext() throws Exception {
384+
public void testInjectContext() throws Exception {
385+
injectContext(new JsonLdOptions());
386+
}
387+
388+
@Test
389+
public void testIssue304_remoteContextAndBaseIri() throws Exception {
390+
injectContext(new JsonLdOptions("testing:baseIri"));
391+
}
392+
393+
private void injectContext(final JsonLdOptions options) throws Exception {
385394

386395
final Object jsonObject = JsonUtils.fromString(
387396
"{ \"@context\":\"http://nonexisting.example.com/thing\", \"pony\":5 }");
388-
final JsonLdOptions options = new JsonLdOptions();
389397

390398
// Verify fails to find context by default
391399
try {

0 commit comments

Comments
 (0)