Skip to content

Commit 53470d6

Browse files
committed
Merge remote-tracking branch 'origin/master' into 1.1-tests
2 parents cfc5d5e + c850eb3 commit 53470d6

37 files changed

+754
-47
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ From Maven
1616
<dependency>
1717
<groupId>com.github.jsonld-java</groupId>
1818
<artifactId>jsonld-java</artifactId>
19-
<version>0.12.4</version>
19+
<version>0.13.0</version>
2020
</dependency>
2121

2222
Code example
@@ -363,11 +363,11 @@ Here is the basic outline for what your module's pom.xml should look like
363363
<parent>
364364
<groupId>com.github.jsonld-java</groupId>
365365
<artifactId>jsonld-java-parent</artifactId>
366-
<version>0.12.4</version>
366+
<version>0.13.0</version>
367367
</parent>
368368
<modelVersion>4.0.0</modelVersion>
369369
<artifactId>jsonld-java-{your module}</artifactId>
370-
<version>0.12.4-SNAPSHOT</version>
370+
<version>0.13.0-SNAPSHOT</version>
371371
<name>JSONLD Java :: {your module name}</name>
372372
<description>JSON-LD Java integration module for {RDF Library your module integrates}</description>
373373
<packaging>jar</packaging>
@@ -490,6 +490,17 @@ Alternatively, we can also host your repository in the jsonld-java organisation
490490
CHANGELOG
491491
=========
492492

493+
### 2019-11-28
494+
* Release 0.13.0
495+
* Bump Jackson versions to latest for security updates (Patch by @afs)
496+
* Do not canonicalise XSD Decimal typed values (Patch by @jhg023)
497+
* Bump dependency and plugin versions
498+
499+
### 2019-08-03
500+
* Release 0.12.5
501+
* Bump Jackson versions to latest for security updates (Patches by @afs)
502+
* IRI resolution fixes (Patch by @fsteeg)
503+
493504
### 2019-04-20
494505
* Release 0.12.4
495506
* Bump Jackson version to 2.9.8

core/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>jsonld-java-parent</artifactId>
66
<groupId>com.github.jsonld-java</groupId>
7-
<version>0.12.5-SNAPSHOT</version>
7+
<version>0.13.1-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>jsonld-java</artifactId>
@@ -74,6 +74,7 @@
7474
<artifactSet>
7575
<includes>
7676
<include>com.google.guava:guava</include>
77+
<include>com.google.guava:failureaccess</include>
7778
</includes>
7879
</artifactSet>
7980
<relocations>
@@ -90,6 +91,12 @@
9091
<exclude>META-INF/maven/**</exclude>
9192
</excludes>
9293
</filter>
94+
<filter>
95+
<artifact>com.google.guava:failureaccess</artifact>
96+
<excludes>
97+
<exclude>META-INF/maven/**</exclude>
98+
</excludes>
99+
</filter>
93100
</filters>
94101
</configuration>
95102
<executions>

core/reports/json-ld-api-tests-skip

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#t0125
196196
https://w3c.github.io/json-ld-api/tests/expand-manifest#t0126
197197
https://w3c.github.io/json-ld-api/tests/expand-manifest#t0127
198198
https://w3c.github.io/json-ld-api/tests/expand-manifest#t0128
199-
https://w3c.github.io/json-ld-api/tests/expand-manifest#t0129
200199
https://w3c.github.io/json-ld-api/tests/expand-manifest#tc001
201200
https://w3c.github.io/json-ld-api/tests/expand-manifest#tc002
202201
https://w3c.github.io/json-ld-api/tests/expand-manifest#tc003
@@ -486,16 +485,8 @@ https://w3c.github.io/json-ld-api/tests/remote-doc-manifest#tla01
486485
https://w3c.github.io/json-ld-api/tests/remote-doc-manifest#tla03
487486
https://w3c.github.io/json-ld-api/tests/remote-doc-manifest#tla04
488487
https://w3c.github.io/json-ld-api/tests/remote-doc-manifest#tla05
489-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0120
490-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0122
491-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0123
492-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0124
493-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0125
494488
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0126
495489
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0128
496-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0130
497-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0131
498-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0132
499490
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc001
500491
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc002
501492
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc003
@@ -587,7 +578,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0125
587578
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te126
588579
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te127
589580
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te128
590-
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te129
591581
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tec01
592582
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tec02
593583
https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tem01

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static com.github.jsonldjava.core.JsonLdConsts.RDF_REST;
77
import static com.github.jsonldjava.core.JsonLdConsts.RDF_TYPE;
88
import static com.github.jsonldjava.core.JsonLdConsts.XSD_BOOLEAN;
9+
import static com.github.jsonldjava.core.JsonLdConsts.XSD_DECIMAL;
910
import static com.github.jsonldjava.core.JsonLdConsts.XSD_DOUBLE;
1011
import static com.github.jsonldjava.core.JsonLdConsts.XSD_INTEGER;
1112
import static com.github.jsonldjava.core.JsonLdConsts.XSD_STRING;
@@ -665,7 +666,10 @@ private Node objectToRDF(Object item) {
665666
return new Literal(Float.toString((float) value),
666667
datatype == null ? XSD_DOUBLE : (String) datatype, null);
667668
} else {
668-
// canonical double representation
669+
// Only canonicalize representation if datatype is not XSD_DECIMAL
670+
if (XSD_DECIMAL.equals(datatype)) {
671+
return new Literal(value.toString(), XSD_DECIMAL, null);
672+
}
669673
final DecimalFormat df = new DecimalFormat("0.0###############E0");
670674
df.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.US));
671675
return new Literal(df.format(value),

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,34 @@ public static String resolve(String baseUri, String pathToResolve) {
261261
}
262262
try {
263263
URI uri = new URI(baseUri);
264+
// URI#resolve drops base scheme for opaque URIs, https://github.com/jsonld-java/jsonld-java/issues/232
265+
if (uri.isOpaque()) {
266+
String basePath = uri.getPath() != null ? uri.getPath() : uri.getSchemeSpecificPart();
267+
// Drop the last segment, see https://tools.ietf.org/html/rfc3986#section-5.2.3 (2nd bullet point)
268+
basePath = basePath.contains("/") ? basePath.substring(0, basePath.lastIndexOf('/') + 1) : "";
269+
return new URI(uri.getScheme(), basePath + pathToResolve, null).toString();
270+
}
271+
// "a base URI [...] does not allow a fragment" (https://tools.ietf.org/html/rfc3986#section-4.3)
272+
uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), null);
264273
// query string parsing
265274
if (pathToResolve.startsWith("?")) {
266-
// drop fragment from uri if it has one
267-
if (uri.getFragment() != null) {
268-
uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, null);
269-
}
270-
// add query to the end manually (as URI.resolve does it wrong)
275+
// drop query, https://tools.ietf.org/html/rfc3986#section-5.2.2: T.query = R.query;
276+
uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, null);
277+
// add query to the end manually (as URI#resolve does it wrong)
278+
return uri.toString() + pathToResolve;
279+
} else if (pathToResolve.startsWith("#")) {
280+
// add fragment to the end manually (as URI#resolve does it wrong)
271281
return uri.toString() + pathToResolve;
272282
}
273-
283+
// ensure a slash between the authority and the path of a URL
284+
if (uri.getSchemeSpecificPart().startsWith("//") && !uri.getSchemeSpecificPart().matches("//.*/.*")) {
285+
uri = new URI(uri + "/");
286+
}
274287
uri = uri.resolve(pathToResolve);
275288
// java doesn't discard unnecessary dot segments
276289
String path = uri.getPath();
277290
if (path != null) {
278-
path = JsonLdUrl.removeDotSegments(uri.getPath(), true);
291+
path = JsonLdUrl.removeDotSegments(path, true);
279292
}
280293
return new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(),
281294
uri.getFragment()).toString();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.jsonldjava.core;
2+
3+
import org.junit.Test;
4+
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import static org.junit.Assert.assertEquals;
10+
11+
public class DecimalLiteralCanonicalTest {
12+
13+
@Test
14+
public void testDecimalIsNotCanonicalized() {
15+
double value = 6.5;
16+
17+
Map<String, Object> innerMap = new HashMap<>();
18+
innerMap.put("@value", value);
19+
innerMap.put("@type", "http://www.w3.org/2001/XMLSchema#decimal");
20+
21+
Map<String, Object> jsonMap = new HashMap<>();
22+
jsonMap.put("ex:id", innerMap);
23+
24+
JsonLdApi api = new JsonLdApi(jsonMap, new JsonLdOptions(""));
25+
RDFDataset dataset = api.toRDF();
26+
27+
List<Object> defaultList = (List<Object>) dataset.get("@default");
28+
Map<String, Object> tripleMap = (Map<String, Object>) defaultList.get(0);
29+
Map<String, String> objectMap = (Map<String, String>) tripleMap.get("object");
30+
31+
assertEquals("http://www.w3.org/2001/XMLSchema#decimal", objectMap.get("datatype"));
32+
assertEquals(Double.toString(value), objectMap.get("value"));
33+
}
34+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.github.jsonldjava.core;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertNotNull;
56

67
import java.io.BufferedReader;
78
import java.io.InputStreamReader;
89
import java.io.Reader;
910
import java.nio.charset.Charset;
11+
import java.util.List;
1012

1113
import org.junit.Test;
1214

@@ -55,4 +57,25 @@ public void testMixedLocalRemoteBaseLocalContextFirst() throws Exception {
5557
assertEquals(expanded, output);
5658
}
5759

60+
@Test
61+
public void testUriResolveWhenExpandingBase() throws Exception {
62+
63+
final Reader reader = new BufferedReader(new InputStreamReader(
64+
this.getClass().getResourceAsStream("/custom/base-0003-in.jsonld"),
65+
Charset.forName("UTF-8")));
66+
final Object input = JsonUtils.fromReader(reader);
67+
assertNotNull(input);
68+
69+
final JsonLdOptions options = new JsonLdOptions();
70+
final List<Object> expanded = JsonLdProcessor.expand(input, options);
71+
assertFalse("expanded form must not be empty", expanded.isEmpty());
72+
73+
final Reader outReader = new BufferedReader(new InputStreamReader(
74+
this.getClass().getResourceAsStream("/custom/base-0003-out.jsonld"),
75+
Charset.forName("UTF-8")));
76+
final Object expected = JsonLdProcessor.expand(JsonUtils.fromReader(outReader), options);
77+
assertNotNull(expected);
78+
assertEquals(expected, expanded);
79+
}
80+
5881
}

core/src/test/java/com/github/jsonldjava/utils/JsonUtilsTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.jsonldjava.utils;
22

3+
4+
import static org.junit.Assert.assertEquals;
35
import static org.junit.Assert.assertTrue;
46

57
import java.io.IOException;
@@ -15,6 +17,19 @@
1517
import com.fasterxml.jackson.databind.ObjectMapper;
1618

1719
public class JsonUtilsTest {
20+
@Test
21+
public void resolveTest() {
22+
final String baseUri = "http://mysite.net";
23+
final String pathToResolve = "picture.jpg";
24+
String resolve = "";
25+
26+
try {
27+
resolve = JsonLdUrl.resolve(baseUri, pathToResolve);
28+
assertEquals(baseUri + "/" + pathToResolve, resolve);
29+
} catch (final Exception e) {
30+
assertTrue(false);
31+
}
32+
}
1833

1934
@SuppressWarnings("unchecked")
2035
@Test
@@ -25,13 +40,12 @@ public void fromStringTest() {
2540

2641
try {
2742
obj = JsonUtils.fromString(testString);
43+
assertTrue(((Map<String, Object>) obj).containsKey("seq"));
44+
assertTrue(((Map<String, Object>) obj).get("seq") instanceof Number);
2845
} catch (final Exception e) {
2946
assertTrue(false);
3047
}
3148

32-
assertTrue(((Map<String, Object>) obj).containsKey("seq"));
33-
assertTrue(((Map<String, Object>) obj).get("seq") instanceof Number);
34-
3549
try {
3650
obj = JsonUtils.fromString(testFailure);
3751
assertTrue(false);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"@context": {
3+
"@base": "http://mysite.net",
4+
"DataSet": "http://schema.org/DataSet",
5+
"CreativeWork": "http://schema.org/CreativeWork"
6+
},
7+
"@graph": [
8+
{
9+
"@type": "CreativeWork",
10+
"@id": "picture.jpg"
11+
},
12+
{
13+
"@id": "./",
14+
"@type": "DataSet"
15+
}
16+
]
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ {
2+
"@id" : "http://mysite.net/picture.jpg",
3+
"@type" : [ "http://schema.org/CreativeWork" ]
4+
}, {
5+
"@id" : "http://mysite.net/",
6+
"@type" : [ "http://schema.org/DataSet" ]
7+
} ]

0 commit comments

Comments
 (0)