⚡ Sangsakala Proxy 🏠 Home
Skip to content

Commit a88eacf

Browse files
committed
Merge branch '304-absoluteContextIsMadeRelative' of https://github.com/jsonld-java/jsonld-java
See #305.
2 parents e5b0b33 + 0ebe491 commit a88eacf

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.LinkedHashMap;
1010
import java.util.List;
1111
import java.util.Map;
12+
import java.util.regex.Pattern;
1213

1314
import com.github.jsonldjava.core.JsonLdError.Error;
1415
import com.github.jsonldjava.utils.JsonLdUrl;
@@ -25,6 +26,7 @@ public class Context extends LinkedHashMap<String, Object> {
2526

2627
private static final long serialVersionUID = 2894534897574805571L;
2728

29+
private static final Pattern URL_PATTERN = Pattern.compile("^https?://.*$", Pattern.CASE_INSENSITIVE);
2830
private JsonLdOptions options;
2931
private Map<String, Object> termDefinitions;
3032
public Map<String, Object> inverse = null;
@@ -141,7 +143,6 @@ && getTermDefinition(activeProperty).containsKey(JsonLdConsts.LANGUAGE)
141143
* @throws JsonLdError
142144
* If there is an error parsing the contexts.
143145
*/
144-
@SuppressWarnings("unchecked")
145146
public Context parse(Object localContext, List<String> remoteContexts) throws JsonLdError {
146147
if (remoteContexts == null) {
147148
remoteContexts = new ArrayList<String>();
@@ -187,7 +188,11 @@ private Context parse(Object localContext, final List<String> remoteContexts,
187188
}
188189
// 3.2)
189190
else if (context instanceof String) {
190-
String uri = (String) result.get(JsonLdConsts.BASE);
191+
String uri = null;
192+
// @base is ignored when processing remote contexts, https://github.com/jsonld-java/jsonld-java/issues/304
193+
if (!URL_PATTERN.matcher(context.toString()).matches()) {
194+
uri = (String) result.get(JsonLdConsts.BASE);
195+
}
191196
uri = JsonLdUrl.resolve(uri, (String) context);
192197
// 3.2.2
193198
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)