GeezerVison is showing github.com — Ignore @base if remote context is not relative · jsonld-java/jsonld-java@45c2942
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/com/github/jsonldjava/core test/java/com/github/jsonldjava/core
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: core/src/main/java/com/github/jsonldjava/core/Context.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -187,7 +187,11 @@ private Context parse(Object localContext, List<String> remoteContexts, |
187 | 187 | } |
188 | 188 | // 3.2) |
189 | 189 | 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 | + } |
191 | 195 | uri = JsonLdUrl.resolve(uri, (String) context); |
192 | 196 | // 3.2.2 |
193 | 197 | if (remoteContexts.contains(uri)) { |
|
Collapse file
Copy file name to clipboardExpand all lines: core/src/test/java/com/github/jsonldjava/core/DocumentLoaderTest.java +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -381,11 +381,19 @@ public void testDisallowRemoteContexts() throws Exception { |
381 | 381 | } |
382 | 382 |
|
383 | 383 | @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 { |
385 | 394 |
|
386 | 395 | final Object jsonObject = JsonUtils.fromString( |
387 | 396 | "{ \"@context\":\"http://nonexisting.example.com/thing\", \"pony\":5 }"); |
388 | | - final JsonLdOptions options = new JsonLdOptions(); |
389 | 397 |
|
390 | 398 | // Verify fails to find context by default |
391 | 399 | try { |
|