Skip to content

Commit c2705f2

Browse files
committed
Handle opaque base IRIs
See #232
1 parent 4eb40f9 commit c2705f2

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎core/src/main/java/com/github/jsonldjava/utils/JsonLdUrl.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,27 @@ public static String resolve(String baseUri, String pathToResolve) {
261261
}
262262
try {
263263
URI uri = new URI(baseUri);
264+
// URI#resolve drops base for opaque URIs, https://github.com/jsonld-java/jsonld-java/issues/232
265+
if(uri.isOpaque()) {
266+
return uri.toString() + pathToResolve;
267+
}
264268
// "a base URI [...] does not allow a fragment" (https://tools.ietf.org/html/rfc3986#section-4.3)
265269
uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), null);
266270
// query string parsing
267271
if (pathToResolve.startsWith("?")) {
268272
// drop query, https://tools.ietf.org/html/rfc3986#section-5.2.2: T.query = R.query;
269273
uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, null);
270-
// add query to the end manually (as URI.resolve does it wrong)
274+
// add query to the end manually (as URI#resolve does it wrong)
271275
return uri.toString() + pathToResolve;
272276
} else if (pathToResolve.startsWith("#")) {
273-
// add fragment to the end manually (as URI.resolve does it wrong)
277+
// add fragment to the end manually (as URI#resolve does it wrong)
274278
return uri.toString() + pathToResolve;
275279
}
276280
uri = uri.resolve(pathToResolve);
277281
// java doesn't discard unnecessary dot segments
278282
String path = uri.getPath();
279283
if (path != null) {
280-
path = JsonLdUrl.removeDotSegments(uri.getPath(), true);
284+
path = JsonLdUrl.removeDotSegments(path, true);
281285
}
282286
return new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(),
283287
uri.getFragment()).toString();

‎core/src/test/java/com/github/jsonldjava/core/ToRDFTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public void toRdfWithHierarchicalBaseIri() throws IOException, JsonLdError {
6565
}
6666

6767
@Test
68-
@Ignore
6968
// See https://github.com/jsonld-java/jsonld-java/issues/232#issuecomment-493454096
7069
public void toRdfWithOpaqueBaseIri() throws IOException, JsonLdError {
7170
testToRdf("/custom/toRdf-0001-in.jsonld", "/custom/toRdf-0003-out.nq", "tag:example/");

0 commit comments

Comments
 (0)